Registry / database / django-linear-migrations

django-linear-migrations

JSON →
library2.19.0pypypi✓ verified 24d ago

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.

pip install django-linear-migrations
INSTALL
IMPORT
SIG · DJANGO-LINEAR-MIGR
D
django-linear-migrations
databasepythonv2.19.0
Install
3.5s avg
Import
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.19.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.5s · import 0.000s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

django_linear_migrations
INSTALLED_APPS = [ # ... 'django_linear_migrations', # ... ]
Add 'django_linear_migrations' to your Django project's INSTALLED_APPS setting.
Command
from django_linear_migrations.management.commands.makemigrations import Command as BaseCommand class Command(BaseCommand): # ... your custom logic pass
from django.core.management.commands.makemigrations import Command
When overriding Django's built-in `makemigrations` or `squashmigrations` with django-linear-migrations, your custom command must subclass `django_linear_migrations.management.commands.makemigrations.Command` (or `squashmigrations.Command`). Ensure your app with the custom command is listed *before* `django_linear_migrations` in `INSTALLED_APPS`.

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.
Debug
Known issues
breakingIn version 2.0.0, the management commands were renamed from using hyphens to underscores to make them importable and extensible. `create-max-migration-files` became `create_max_migration_files` and `rebase-migration` became `rebase_migration`.
fix
Update calls to the management commands (e.g., in CI scripts) to use the new underscore-separated names.
affects: >=2.0.0
breakingAs of version 2.19.0, support for Python 3.9 has been dropped. The library now requires Python 3.10 or newer.
fix
Upgrade your Python environment to 3.10 or a later supported version.
affects: >=2.19.0
gotchaAutomatic detection of 'first-party' (project) apps can sometimes fail, especially with editable package installations (`pip install -e`). This can lead to `max_migration.txt` files being created for third-party apps.
fix
Explicitly define your first-party apps using the `FIRST_PARTY_APPS` setting in your `settings.py`. For example: `FIRST_PARTY_APPS = ['your_app_name', 'another_app']` and combine it into `INSTALLED_APPS`: `INSTALLED_APPS = FIRST_PARTY_APPS + ['django_linear_migrations', ...]`.
affects: all
gotchaIf you override Django's built-in `makemigrations` or `squashmigrations` commands in your project, your custom command must subclass the version provided by `django-linear-migrations` to ensure its functionality. Additionally, your app containing the custom command must be listed *above* `django_linear_migrations` in `INSTALLED_APPS`.
fix
See the `imports` section for the correct subclassing pattern. Adjust `INSTALLED_APPS` order as necessary.
affects: all
gotchaThe `rebase_migration` command does not currently support rebasing multiple migrations within the same app. Attempting this may lead to unexpected behavior or incomplete rebasing.
fix
If your feature branch has multiple commits that create migrations, it's recommended to squash those commits into a single migration before rebasing your branch onto the main branch (e.g., using `git rebase -i --keep-base main`).
affects: all
gotchaThe `rebase_migration` command does not guarantee that its edits to migration files will match your project's code style. It will attempt to format with Black if installed, but manual reformatting may still be needed.
fix
After running `python manage.py rebase_migration <app_label>`, run your code formatter (e.g., Black, isort) on the modified migration files. If you use pre-commit hooks, remember that Git does not invoke hooks during rebase commits, so you might need to run `pre-commit run` manually on the changed files.
affects: all
Errors
Common errors & fixes
CONFLICT (content): Merge conflict in <app_path>/migrations/max_migration.txt
Multiple developers have created new migrations for the same Django app concurrently, leading to conflicting updates in the `max_migration.txt` file during a Git merge or rebase.
fix
Rebase your feature branch onto the main branch, resolve the `max_migration.txt` conflict by accepting the incoming change, and then run `python manage.py rebase_migration <app_label>` to re-order your local migration and update the `max_migration.txt` file correctly.
dlm.E004: <app_label>'s max_migration.txt contains '<max_migration_name>', but the latest migration is '<real_max_migration_name>'
The `max_migration.txt` file for a given Django app is out of sync with the actual latest migration file in that app's migrations directory.
fix
Manually update the `max_migration.txt` file to contain the exact name of the latest migration file, or run `python manage.py create_max_migration_files --recreate <app_label>` to automatically regenerate it.
dlm.E005: Conflicting migrations detected; multiple leaf nodes in the migration graph: <conflicting_migrations>
Despite `django-linear-migrations` attempting to prevent them, a branched migration history (multiple 'leaf nodes') has been detected, likely due to mishandling of `max_migration.txt` or `rebase_migration`, or if third-party apps have non-linear migrations.
fix
For first-party apps managed by `django-linear-migrations`, use `python manage.py rebase_migration <app_label>` to resolve the conflict. For complex cases or third-party apps, manually inspect migration dependencies and consider squashing migrations or resetting migration history in a development environment.
django-linear-migrations creates max_migration.txt for third-party apps
The automatic detection of first-party Django apps by `django-linear-migrations` can sometimes fail, leading to `max_migration.txt` files being created for third-party apps that should not be managed by the library.
fix
Explicitly define your first-party apps by setting `FIRST_PARTY_APPS = ['your_app_name', 'another_app']` in your `settings.py` and ensure `INSTALLED_APPS = FIRST_PARTY_APPS + ['django_linear_migrations', ...]` to prevent files from being created for unintended apps.
Upgrade
Version history
2.19.0latest on PyPI · released Sep 18, 2025
Audit
Dependencies
DjangorequiredCore framework dependency. Supports Django 4.2 to 6.0.
PythonrequiredRuntime environment. Supports Python 3.10 to 3.14.
blackoptionalUsed by `rebase_migration` command for formatting modified migration files, if available.
Agent activity
5 hits · last 30 days
node
4
Resources
django-linear-migrations — pip install django-linear-migrations · libregistry