#36840: makemigrations not detecting adding UniqueConstraint to models.py
---------------------------------+-----------------------------------------
Reporter: ClashCityWomble | Type: Uncategorized
Status: new | Component: Migrations
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
I recently updated my Django project to use Postgres instead od SQLLite. I
wanted to add some composite unique keys to a couple of tables but after
adding the constraint to the model, makemigrations doesnt detect any
changes. If i make any other changes to the model like adding a new field
then it detects that fine, creates the migration and I can apply it no
problem. I'm a bit stuck. Do I just create the constraint through running
some Postgres SQL or should it be managed through the models? Any help
gratefully received!
{{{
class CollectionSegment(models.Model):
constraints = [
models.UniqueConstraint(
fields=['collection', 'athletesegment'],
name='composite_unique_key')
]
collection = models.ForeignKey(Collection, on_delete=models.CASCADE)
athletesegment = models.ForeignKey(AthleteSegment,
on_delete=models.CASCADE)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36840>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019b866af94e-f335a010-f925-4842-aefe-4508ff4e951f-000000%40eu-central-1.amazonses.com.