-
Notifications
You must be signed in to change notification settings - Fork 50
Protect foreign key constraint between imagelist_images
and imagelist
#356
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to fix this that doesn't involve changing the migration history? If not this LGTM but I think leaving the migration history as immutable is preferrable to modifying it.
Also if we go with this then let's go ahead and use the full name of the migration rather than an abbreviation when we run that script in prod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @dhruvkb and @AetherUnbound, this is great.
747b23d
to
2181e32
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Django has a command for squashing migrations, didn't it work here? Altering the old ones manually is not a good practice. Otherwise, it seems to work well.
@krysal the reason I did not squash the migrations and rather edit them by hand was that this approach removes the need to actually run any migrations in production. Editing migrations is bad but, in our case, the prod environment and dev are quite out of sync so the usual guidelines need to be bent a little to bring all environments to the same level again. |
This migration ran successfully on a snapshot of prod ✔️ |
Description
Since migration 0002 changes the primary key on the
ImageList
model, it breaks the foreign key constraint that refers to that column. This PR merges 0002 into 0001 so that the constraint is set after the changes to the primary key.Credits to @AetherUnbound for pointing this bug out in prod.
Testing Instructions
docker-compose exec -T web python manage.py migrate
imagelist_images
table.FOREIGN KEY (image_id) REFERENCES image(id)
FOREIGN KEY (imagelist_id) REFERENCES imagelist(id)
Since 0002 is already a performed migration, removing the corresponding file might interfere with rollbacks etc. To prevent potential future problems, remove the entry from the
django_migrations
table.Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin