Skip to main content

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-fixer which is not actively maintained by the author.

  • Detects conflicting leaf nodes and renumbers local migrations to form a single linear chain.
  • Rewrites dependencies to 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 migrations error, 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 under tests/unit.
  • make tests-e2e — Discover and run tests under tests/e2e (safe if empty).
  • make builduv sync --extra dev then uv build to produce wheels/sdist.
  • make distributetwine check then upload artifacts in dist/ to PyPI.

Notes:

  • Test runs set PYTHONPATH=src so the package imports without installation.
  • build and distribute require uv to be installed and available on PATH.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_modern_migration_fixer-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_modern_migration_fixer-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file django_modern_migration_fixer-0.1.1.tar.gz.

File metadata

File hashes

Hashes for django_modern_migration_fixer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 51f168b94b0f160903d319ea6edb564ca5bc473b3fbde8c7cb5a537181b33ac4
MD5 6fc3b235887f6daf2127939b7d7a41b7
BLAKE2b-256 5f6d26a4dc6dcd4fe09f8d2771ccdf10ca4fb770e22fa5d1e6f2ada6569f948b

See more details on using hashes here.

File details

Details for the file django_modern_migration_fixer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_modern_migration_fixer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 75c3587165d5020e8fb314906938be088e9f819976432f5d9a342090430a1774
MD5 43967d58289a9e204ad1660a8a1be7c7
BLAKE2b-256 14fbc2cfca9c91bcec84679392bcd5bbba1b05bb6625eb16104ef391f88715a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page