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
I recently ran into an issue when squashing migrations. The issue is that there is a duplicate index in the database. We're probably going to work around it by skipping step 3 below, but I thought it still makes sense to create an issue, in the case someone else runs into it.
I managed to find a minimal reproducible example and uploaded it here
The steps I took to create this example:
Create new django project and new app
Create ModelA and ModelB, where ModelB has a nullable ForeignKey relation to ModelA, generate migrations
Create a data migration where you create some objects of ModelA and perform some filter(..).update(...)s on ModelB
Alter the ForeignKey from ModelB to ModelA to be non-nullable. Generate migrations, selecting option 2 (don't specify a default) when prompted by Django.
Squash these migrations
The result in the database is:
There are two indexes here, where I would expect only 1.
The peculiar thing is that without step 3, only 1 unique index is created (as I would expect). I haven't investigated if the issue also occurs when you perform less or different creations/updates in step 3.
The issue doesn't occur when using sqlite as backend, but it also occurs with the django-mssql-backend.