You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like running manage.py makemigrations with this library does not automatically create a migration that removes a unique constraint on a table when the unique_together field changes for a model.
Steps to reproduce:
Create a model (Model1) with a foreign key to another model (Model2).
Add a unique field to to Model2 (e.g. some natural key CharField(unique=True))
Add Model2 as a part of a unique_together field set for Model1.
This wipes the previous constraints. And then we create a followup migration to create the unique_together field. Having to create manual migrations like this is error prone.
It looks like running
manage.py makemigrations
with this library does not automatically create a migration that removes a unique constraint on a table when theunique_together
field changes for a model.Steps to reproduce:
Model1
) with a foreign key to another model (Model2
).Model2
(e.g. some natural keyCharField(unique=True)
)Model2
as a part of aunique_together
field set forModel1
.manage.py makemigrations
manage.py migrate
Model2
object from the db, replacing it inunique_together
with some other field.manage.py makemigrations
manage.py migrate
The last step should produce the following error:
We are currently able to workaround this by creating manual database migrations that look like this:
This wipes the previous constraints. And then we create a followup migration to create the unique_together field. Having to create manual migrations like this is error prone.
See also this ticket where a similar problem was identified and fixed for MySQL:
https://code.djangoproject.com/ticket/24757
And for PostgreSQL:
https://code.djangoproject.com/ticket/23065
https://code.djangoproject.com/ticket/25648
I think we need a similar fix for MSSQL.
The text was updated successfully, but these errors were encountered: