Migration fails when removing explicit primary key (Postgres)
|Reported by:||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The automatic migration created by migrate fails when
- a table was created with a field where "primary_key=True" is specified.
- data is added to the table
- The model is modified so that no field is primary key, and Django auto-creates "id" field.
To reproduce the problem:
- create new model, set some field as primary key
- set up migrations with initial migration
- modify model so field is not primary key
- generate migration
- will ask for default value for auto-generated ID field
- will try to create id field as primary key, before modifying existing key
- remove default from models.AutoField() call
- reverse order of operations so AlterField() comes before AddField()
I'm attaching a session log with a complete transcript.
Change History (4)
comment:1 Changed 3 years ago by
|Component:||Database layer (models, ORM) → Migrations|
|Triage Stage:||Unreviewed → Accepted|
|Type:||Uncategorized → Bug|