Opened 9 years ago
Last modified 9 years ago
#25945 closed Bug
Unabled to refer to partially-run squashed migrations in newer migrations. — at Initial Version
Reported by: | Jarek Glowacki | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | dev |
Severity: | Normal | Keywords: | make squash migrations partially run dependencies |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
From Django docs:
"These files are marked to say they replace the previously-squashed migrations, so they can coexist with the old migration files, and Django will intelligently switch between them depending where you are in the history. If you’re still part-way through the set of migrations that you squashed, it will keep using them until it hits the end and then switch to the squashed history, while new installs will just use the new squashed migration and skip all the old ones."
However there seems to be a caviot in that you can't refer to partially squashed migrations.
Example:
my_app/migrations/ 0001_initial.py 0002_blah.py -> dep on 0001_initial 0001_initial_squashed_0002_blah.py -> replaces 0001_initial and 0002_blah 0003_ohnoes.py -> dep on ????
If we try to make 0003 depend on 0001_initial_squashed_0002_blah, then we get a NodeNotFoundError if the database is only up to 0001_initial: it has 'intelligently switched' to the unsquashed reality in which 0001_initial_squashed_0002_blah does not exist.
Conversely if we try to make 0003 depend on 0002_blah, then we get a NodeNotFoundError when trying to create a new database: it has 'intelligently switched' to the squashed reality in which 0002_blah does not exist.
Proposed solution: Use
dependencies = [('my_app', '0001_initial_squashed_0002_blah'),]
and for cases where the migration tree does not contain 0001_initial_squashed_0002_blah, have it inspect the 'replaces' list in 0001_initial_squashed_0002_blah.py, pick out the most recent migration (ie 0002_blah.py) and use that instead.
I'm happy to implement this myself if given the thumbs up for the proposed approach.