Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#23794 closed Bug (fixed)

FieldDoesNotExist error in migration with deleted fields and unique_together constraint

Reported by: Nico Benitez Owned by: Andrzej Pragacz
Component: Migrations Version: dev
Severity: Normal Keywords: migration unique_together removefield
Cc: info+coding@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by berto)

I had a model that had a ForeignKey field and a unique_together constraint involving that field. I deleted both the field and the unique_together constraint in my model and ran makemigrations. The migration created RemoveField operation and a AlterUniqueTogether operation with unique_together=set([]). When I tried to run the migration, a django.db.models.fields.FieldDoesNotExist exception occured. I edited the migration manually to put the AlterUniqueTogether operation before the RemoveField operation and then the migration worked.

NOTE: After upgrading, you must remove the bad migration file and re-run makemigrations or manually move the AlterUniqueTogether operation manually as stated above; i.e. upgrading does not fix the existing migration.

Change History (8)

comment:1 by Simon Charette, 9 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.7master

Managed to reproduce against master.

comment:2 by Andrzej Pragacz, 9 years ago

Owner: changed from nobody to Andrzej Pragacz
Status: newassigned

comment:3 by Andrzej Pragacz, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:4 by Simon Charette, 9 years ago

Has patch: set
Resolution: fixed
Status: closednew

comment:5 by Markus Holtermann, 9 years ago

Cc: info+coding@… added

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 72729f844e0dd9bd01b3874171b89ab0d136a40e:

Fixed #23794 -- Fixed migrations crash when removing a field that's part of index/unique_together.

comment:7 by Tim Graham <timograham@…>, 9 years ago

In feded19104b14bc28aaccf550265157df84593ba:

[1.7.x] Fixed #23794 -- Fixed migrations crash when removing a field that's part of index/unique_together.

Backport of 72729f844e0dd9bd01b3874171b89ab0d136a40e from master

comment:8 by berto, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top