what is it?
a django module that enforces a linear migration history for your apps
how it works
- uses
makemigrationsto record the name of the latest migration in a per-appmax_migration.txtfiles - these files will then cause a merge conflict in your source control tool (git, mercurial, etc.) in the case of migrations being developed in parallel
commands
create_max_migration_files
this management command creates max_migration.txt files for all first party apps, or the given labels. it’s used in initial installation of django-linear-migrations, and for recreating
python manage.py create_max_migration_files [app_label [app_label ...]] --dry-run --recreate- pass the
--dry-runflag to only list themax_migration.txtfiles that would be created. - pass the
--recreateflag to re-create files that already exist. This may be useful after altering migrations with merges or manually
rebase_migration
following a conflicted “rebase” operation in Git, run it with the name of the app to auto-fix the migrations for
python manage.py rebase_migration <app_label>the command uses the conflict information in the max_migration.txt file to determine which migration to rebase
general workflow
steps to take if git has a merge conflict on one of the max_migration.txt files
for example, in the books app, the max_migration.txt file contains 0002_author_nicknames. you’re trying to add a 0002_longer_titles migration
-
abort the merge, if relevant
git merge --abort -
reverse the new migration:
python manage.py migrate books 0001 -
fetch the latest code
git checkout master git pull -
merge master into branch (will cause merge conflict)
git checkout titles git merge master -
use
rebase_migrationto automatically fix thebooksmigration history
python manage.py rebase_migration booksthis will rename 0002_longer_titles.py to 0003_longer_titles.py , modify the dependencies = [...] declaration inside it, and update the migration named in max_migration.txt