Opened 9 years ago

Closed 9 years ago

#25690 closed Bug (duplicate)

Migration operations should be ordered to prevent all columns from being removed

Reported by: Matthew Crowson Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords: mysql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When a migration contains changes to all fields, and a removal of the pk field and the addition of a new pk field, the migration fails. This is due to the migrations removals before the additions. This yields the warning that an empty table should be dropped before the new fields can be added.

django.db.utils.OperationalError: (1090, "You can't delete all columns with ALTER TABLE; use DROP TABLE instead")

By moving the migration commands I was able to get the migration to perform successfully.
First: Remove the existing pk
Second: Add the new pk
Lastly: the migration commands as they were initially created.

Change History (3)

comment:1 by Simon Charette, 9 years ago

Keywords: mysql added
Summary: Order of Migrations Commands Needs to Allow for All Field ChangesMigration operations should be ordered to prevent all columns from being removed

I suppose this happens on MySQL?

comment:2 by Paul, 9 years ago

This does indeed happen on MySQL when removing the last column from a table. The problem can be worked around by changing the order of operations in the migration.

Maybe it would be a good idea to drop and recreate the table if all columns are dropped?

comment:3 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #24424

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