What's Actually Happening
Django migrations conflict when multiple developers create migrations in parallel branches. Applying migrations fails with dependency errors.
The Error You'll See
```bash $ python manage.py migrate
django.db.migrations.exceptions.InconsistentMigrationHistory: Migration myapp.0002_add_field is applied before its dependency myapp.0001_initial ```
Why This Happens
- 1.Parallel development - Multiple migration branches
- 2.Wrong merge order - Migrations merged incorrectly
- 3.Dependency conflict - Circular or missing dependencies
- 4.Applied out of order - Migrations applied in wrong sequence
Step 1: Check Migration Status
```bash # List migrations: python manage.py showmigrations
# Check migration plan: python manage.py migrate --plan
# Check squashed: python manage.py showmigrations --list ```
Step 2: Rollback Conflicting Migration
```bash # Rollback to previous: python manage.py migrate myapp 0001
# Fake migration: python manage.py migrate --fake myapp 0002 ```
Step 3: Merge Migrations
```bash # Create merge migration: python manage.py makemigrations --merge
# Or manually create: python manage.py makemigrations myapp --name merge_migrations ```
Step 4: Fix Dependencies
# In migration file:
dependencies = [
('myapp', '0001_initial'),
('otherapp', '0003_add_field'),
]Django Migration Checklist
| Check | Command | Expected |
|---|---|---|
| Show migrations | showmigrations | All applied |
| No conflicts | migrate --plan | No errors |
| Dependencies | check files | Correct |
Verify the Fix
python manage.py migrate
# Output: No migrations to applyRelated Issues
- [Fix Django Migration Apply Failed](/articles/fix-django-migration-apply-failed)
- [Fix Django Model Not Found](/articles/fix-django-queryset-n-plus-one)