Skip to content

Django Migration Conflict Fix

DodaTech Updated 2026-06-24 1 min read

In this tutorial, you'll learn about Django Migration Conflict Fix. We cover key concepts, practical examples, and best practices.

The Problem

Running migrate gives Conflicting migrations detected; multiple leaf nodes in the migration graph. Two developers created migrations from the same parent.

Quick Fix

Step 1: Identify conflicts

python manage.py migrate myapp --list

Step 2: Merge migrations

python manage.py makemigrations --merge

Step 3: Apply the merge

python manage.py migrate myapp

Step 4: Manual merge

class Migration(migrations.Migration):
    dependencies = [
        ('myapp', '0002_auto_20240624_1234'),
        ('myapp', '0002_auto_20240624_5678'),
    ]
    operations = []

Step 5: Squash old migrations

python manage.py squashmigrations myapp 0003

Prevention

  • Never delete applied migrations.
  • Create one migration per feature branch.
  • Communicate with team before creating migrations.

Common Mistakes with migration conflict

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world DJANGO code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is a Django migration conflict?

Two migration files with the same parent but different content, usually from team members working in parallel.

Can I delete conflicting migrations?

Only if they have not been applied. Check with python manage.py showmigrations.

How to prevent team migration conflicts?

Assign one dev to create migrations, or merge feature branches sequentially.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro