Opened 8 years ago

Last modified 8 years ago

#27121 closed Bug

Migrate Fails When Column is Deleted and Unique Together is modified in the same migration — at Initial Version

Reported by: Chris Reedy Owned by: nobody
Component: Migrations Version: 1.9
Severity: Normal Keywords: migration failure no field
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I discovered a bug that causes a migration to fail when a column is deleted in a migration and unique together is modified in the same migration. The following are the steps to reproduce the bug:

# Consider this your model:
class Fruit (models.Model):

taste = models.CharField(max_length=40)
color = models.CharField(max_length=40)
shape = models.CharField(max_length=40)

class Meta:

unique_together = ('taste', 'color', 'shape')

Now, if you delete the field 'shape' and remove it from the unique together in the same migration so the model looks as follows:

# Updated model:
class Fruit (models.Model):

taste = models.CharField(max_length=40)
color = models.CharField(max_length=40)

class Meta:

unique_together = ('taste', 'color')

Migration will fail in modifying the unique_together and throw an error that the Fruit has no field named 'shape' I think that this is because the delete of the column is processed before the unique index is updated.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top