what is it?

a django module that enforces a linear migration history for your apps

pypi link

how it works

  • uses makemigrations to record the name of the latest migration in a per-app max_migration.txt files
  • 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-run flag to only list the max_migration.txt files that would be created.
  • pass the --recreate flag 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_migration to automatically fix the books migration history

python manage.py rebase_migration books

this 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