Opened 6 years ago

Closed 6 years ago

#29495 closed Bug (duplicate)

When altering unique_together and removing a field, migrations may get wrong order.

Reported by: Curtis Maloney Owned by: nobody
Component: Migrations Version: 2.0
Severity: Normal Keywords: migrations
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 just ran into a case where I was updating a model Trip, replacing one FK (owner) with another.
The model had an existing unique_together constraint including the old FK.

I'd written and applied migrations adding the new FK and setting its value.
When I created the migration to remove the old FK, the RemoveField was inserted _before_ the AlterUniqueTogether.

Since the field was removed first, the error comes:

django.core.exceptions.FieldDoesNotExist: Trip has no field named 'owner'

I fixed it by manually reordering the operations in the migration.

Change History (1)

comment:1 by Tim Graham, 6 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #26180.

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