Resolve migration conflicts¶
When you're rebasing or merging branches, a conflict in max_migration.txt signals that numbered migration files are also conflicting. Normally, migrations with the same number would go undetected during a git merge/rebase because Django generates unique filenames for each oneābut django-linear-migrations surfaces this conflict by flagging it in max_migration.txt.
You can resolve most migration conflicts using the rebase_migration command provided by the library.
Step-by-step resolution¶
Before you rebase¶
You're on your feature branch with all migrations applied and ready to rebase onto upstream/main.
-
Start the rebase
Git will pause and report a conflict in
core/migrations/max_migration.txt. -
Note the conflicting migration numbers
For example, if the conflict involves
core/0025andcore/0027, the lowest number iscore/0025. You'll need this later.
Resolve the conflict¶
-
Abort the rebase
-
Roll back your local database to the migration before the conflict
Since the conflicting migrations need to be reapplied, roll back to the previous migration (e.g.,
core/0024): -
Restart the rebase
-
Auto-resolve migration conflicts
-
Resolve any code conflicts manually as needed
-
Reapply all migrations
-
Run pre-commit checks
-
Stage your changes
-
Complete the rebase
When to use this¶
- Updating a PR: You've opened a PR and want to incorporate the latest changes from
upstream/main - Merging a PR: You're merging a feature branch and need to resolve migration conflicts with
upstream/main
Who should use this¶
- Developers and maintainers