Fix conflicting Django migrations (numbered) with robust git + worktree support
Project description
django-modern-migration-fixer
Fix conflicting Django migrations (numbered styles) using plain git CLI, with robust support for normal repos and git worktrees. No GitPython dependency.
This is a fork and drop-in replacement for django-migration-fixe[https://github.com/tj-django/django-migration-fixer] which is not actively maintained by the author.
- Detects conflicting leaf nodes and renumbers local migrations to form a single linear chain.
- Rewrites
dependenciesto point to the last migration on the default branch. - Works in git worktrees by discovering the repo root via
git rev-parse --show-toplevel.
Install
uv pip install django-modern-migration-fixer
Add to your Django settings:
INSTALLED_APPS = [
# ...
"django_modern_migration_fixer",
# ...
]
Usage
./manage.py makemigrations --fix [apps...]
Useful flags:
-b, --default-branch: Name of the default branch (default:master).-r, --remote: Git remote (default:origin).-s, --skip-default-branch-update: Skip fetching remote default branch.-f, --force-update: Force update the default branch refs before fixing.
Examples:
./manage.py makemigrations --fix
./manage.py makemigrations --fix -b master --skip-default-branch-update
./manage.py makemigrations --fix -r upstream --force-update
How it works
- On a
Conflicting migrationserror, the command:- Verifies the repo is clean.
- Optionally fetches the default branch.
- Resolves default-branch and HEAD SHAs robustly.
- Loads the migration graph and finds conflicts per app.
- Filters changed migration files under the app’s migration folder between default SHA and HEAD.
- Renumbers local files and rewrites dependencies to form a single chain.
Limitations
- Only supports numbered migration file names (e.g.,
0001_initial). Non-numbered names fail fast with a clear message. - Cross-app dependency rewrites beyond simple renumbering are out of scope.
Development
uv sync --extra dev
uv run ruff check --fix . && uv run ruff format .
uv run -m unittest
uv build && uvx twine check dist/*
Make targets
Convenient shortcuts are available via make:
make tests— Run unit and e2e tests (unittest discovery).make tests-unit— Discover and run tests undertests/unit.make tests-e2e— Discover and run tests undertests/e2e(safe if empty).make build—uv sync --extra devthenuv buildto produce wheels/sdist.make distribute—twine checkthen upload artifacts indist/to PyPI.
Notes:
- Test runs set
PYTHONPATH=srcso the package imports without installation. buildanddistributerequireuvto be installed and available on PATH.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_modern_migration_fixer-0.1.0.tar.gz.
File metadata
- Download URL: django_modern_migration_fixer-0.1.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406805d79777e7c76cfba55283b38bedb8c2cad5140dee7d85455fe3da089dd4
|
|
| MD5 |
72dab0dc3f295e10891e4f4c28d27d92
|
|
| BLAKE2b-256 |
d1155a1b0074436c45ed9efe46d0a351e47cd5bc00ff107a804a12cd5a98b8a3
|
File details
Details for the file django_modern_migration_fixer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_modern_migration_fixer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9ef5ff5b8b2ac08d34df53804a7298110113f5823906fbc64bc18e472bdfd61
|
|
| MD5 |
2d7cd3f20fa013a7e39d222f0359094e
|
|
| BLAKE2b-256 |
de15213296c79155163b3202996fbb7a0b06d1bebf854aa481cae30a78a34309
|