Opened 21 months ago
Last modified 20 months ago
#34333 closed Bug
Django migrations adds constraint before adding field — at Initial Version
Reported by: | Raphael Beekmann | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 4.1 |
Severity: | Normal | Keywords: | migration, constraint, field |
Cc: | Durval Carvalho, David Wobrock | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hello,
I have a model, already created through previous migrations, and in a new migration I added a new field with a UniqueConstraint.
The model looks like this (the new field is 'type') :
class Model(models.Model): name = models.CharField() date = models.DateField() type = models.ForeignKey(OtherModel) class Meta: constraints = ( models.UniqueConstraint(fields=('date', 'type'), name='unique_date_for_type'), )
When I run the makemigrations script it adds first the constraint and then the new field. That occurs an error when executing the migration :
django.core.exceptions.FieldDoesNotExist: DailyTask has no field named 'type'
I have to manually move the adds of the constraint before the adds of the new field in the migration file to make it work.
Note:
See TracTickets
for help on using tickets.