Django "Conflicting migrations detected" - Merge Branches
Two migrations in the same app share the same parent, leaving the migration graph with more than one leaf. Django cannot pick a single linear path until you add a merge migration that joins them.
What this error means
migrate or makemigrations --check fails reporting conflicting migrations / multiple leaf nodes for an app. It appears after two branches each created a migration on top of the same previous one and both merged.
CommandError: Conflicting migrations detected; multiple leaf nodes in the
migration graph: (0007_a, 0007_b in orders).
To fix them run 'python manage.py makemigrations --merge'Common causes
Two branches forked the same parent migration
Each branch ran makemigrations on top of, say, 0006, producing two 0007_* leaves. Merging both branches leaves the app with two leaf nodes.
No merge migration created
A fork is legitimate, but Django needs an explicit merge migration to rejoin the two leaves into a single linear head.
How to fix it
Create a merge migration
Let Django generate a migration that depends on both leaves, rejoining the graph.
python manage.py makemigrations --merge
git add orders/migrations/0008_merge_*.pyOr rebase one migration onto the other
- Edit one branch’s migration
dependenciesto point at the other branch’s leaf. - This linearizes the graph into a single chain with one leaf.
- Prefer the merge migration when both branches are already shared.
How to prevent it
- Run
makemigrations --checkin CI so multiple leaves are caught early. - Rebase/merge migration branches before merging feature branches.
- Coordinate so two branches don’t fork the same parent migration unnoticed.