Django Linear Migrations

2.19.0 · active · verified Sat Apr 11

django-linear-migrations is a Django app that enforces a linear migration history in your project, preventing common issues caused by concurrent migration development and merge migrations. It achieves this by introducing `max_migration.txt` files for each app, which will conflict in version control (e.g., Git) if multiple branches add migrations concurrently. The library, currently at version 2.19.0, is actively maintained with frequent releases.

Warnings

Install

Imports

Quickstart

After installation, add `django_linear_migrations` to your `INSTALLED_APPS`. Run `create_max_migration_files --dry-run` to verify first-party app detection, then run `create_max_migration_files` to generate `max_migration.txt` files for your apps. These files track the latest migration and will cause Git conflicts if new migrations are created on divergent branches, forcing a linear history. The `rebase_migration` command can help resolve these conflicts automatically.

# 1. Install the library
pip install django-linear-migrations

# 2. Add to INSTALLED_APPS in settings.py
# settings.py
INSTALLED_APPS = [
    # ... your first-party apps first
    'your_app_name',
    'django_linear_migrations',
    # ... other third-party apps
]

# Optional: Explicitly define first-party apps if auto-detection fails (e.g., with editable installs)
# settings.py
# FIRST_PARTY_APPS = ['your_app_name']
# INSTALLED_APPS = FIRST_PARTY_APPS + ['django_linear_migrations', ...]

# 3. Check automatic detection of first-party apps (dry run)
python manage.py create_max_migration_files --dry-run

# 4. Create initial max_migration.txt files
python manage.py create_max_migration_files

# Now, makemigrations will automatically update max_migration.txt, 
# and `git rebase` or `git merge` will expose migration conflicts.

view raw JSON →