-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't import plugin models in main migrations #25
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.
Couple of questions.
model_name='imagerevision', | ||
name='revisionpluginrevision_ptr', | ||
), | ||
migrations.DeleteModel( |
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.
Just curious - do Django's automatically-generated migrations remove each field like this before deleting models?
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.
I think these were just the foreign keys, removed separately to avoid referential integrity problems when dropping the tables. As I noted in my other reply, this is a fairly tangled pair of models.
field=models.OneToOneField(related_name='current_set', null=True, to='wiki_attachments.AttachmentRevision', blank=True, help_text='The revision of this attachment currently in use (on all articles using the attachment)', verbose_name='current revision'), | ||
preserve_default=True, | ||
), | ||
] |
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.
Why the separateAddField
s after the CreateModel
s? Is this just several migrations from upstream squashed together?
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.
This is what was in our original 001_initial
migration for the wiki app, copied over verbatim. This was a particularly tricky case because AttachmentRevision
has a foreign key to itself, plus it and Attachment
have foreign keys to each other. I think Django just erred on the side of caution and added each of the foreign keys individually after creating the tables.
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.
👍
a8151e2
to
65514af
Compare
While working on the switch from nose to pytest in edx-platform, I discovered that we import models from some of the wiki plugins in the main wiki app's migrations. We don't run migrations before starting tests, but we do have a test which verifies that we don't have model changes which aren't reflected in our migrations. And we don't actually use those plugins, so those models aren't found when preparing the database for a test run. So depending on exactly when this test is run, it can break subsequent tests which delete users because after importing those model files, Django now expects there to be tables for models in them which have foreign keys to user records.
Fixing this by doing the following:
makemigrations
won't care about the fact that those field attributes changed.