Detect, diagnose, and auto-fix Django migration problems in Git workflows
Project description
django-migraid
Detect, diagnose, and auto-fix Django migration problems in Git workflows.
The Problem
Two developers branch from main at migration 0004. Both generate 0005_*.py. Main merges one. The second developer's rebase leaves them with a conflict that makemigrations --merge doesn't cleanly handle in rebase-based workflows. django-migraid fixes this — and ten other common migration pain points.
Installation
pip install django-migraid
Add to INSTALLED_APPS:
INSTALLED_APPS = [
...
"migraid",
]
Quick Start
# Diagnose all migration issues in your project
python manage.py migraid doctor
# Rebase your branch's migrations onto main
python manage.py migraid rebase --base main --dry-run
# Fix conflicting leaf migrations
python manage.py migraid fix-conflicts --dry-run
# Fix out-of-order numbering
python manage.py migraid renumber myapp --dry-run
# Remove stale django_migrations rows
python manage.py migraid prune
# Visualize the migration DAG
python manage.py migraid graph myapp --format mermaid
Problems This Solves
| Issue | Code | Command |
|---|---|---|
| Conflicting leaf migrations (parallel development) | E001 | fix-conflicts |
| Circular migration dependencies | E002 | — (reports) |
| Out-of-order / gap numbering after rebase | E003 | renumber |
| Dependency on a deleted migration | E004 | — (reports) |
Stale django_migrations rows |
W001 | prune |
RunPython without reverse_code |
W002 | — (reports) |
| Squashed migration with old files still present | W003 | — (reports) |
| Merge migrations in a rebase-workflow repo | W004 | rebase |
| Non-deterministic dependency ordering | W005 | — (reports) |
| Cross-app dependency risks | I001 | — (reports) |
--fake / --fake-initial footgun patterns |
I002 | — (reports) |
Command Reference
doctor
Read-only diagnostic. Reports every detected issue with severity.
python manage.py migraid doctor [--app LABEL] [--format text|json]
rebase
Renumber local branch migrations to follow the latest from a target branch.
python manage.py migraid rebase [--base BRANCH] [--app LABEL] [--dry-run] [--yes] [--force] [--allow-applied]
fix-conflicts
Resolve multiple-leaf conflicts by linearizing the fork.
python manage.py migraid fix-conflicts [--app LABEL] [--dry-run] [--yes] [--force] [--allow-applied]
renumber
Fix gap or duplicate numbering in a single app's migrations.
python manage.py migraid renumber <app> [--dry-run] [--yes] [--force] [--allow-applied]
prune
Remove orphaned django_migrations rows for migrations no longer on disk.
python manage.py migraid prune [--dry-run] [--yes] [--allow-applied]
graph
Print or export the migration DAG.
python manage.py migraid graph [app] [--format mermaid|dot|ascii] [--output FILE]
Safety Model
Every mutation command:
- Checks for uncommitted git changes (bypass with
--force) - Guards against rewriting already-applied migrations (bypass with
--allow-applied) - Creates a
migraid-backup-<timestamp>git ref before any writes - Shows a diff-style preview before making changes
- Asks for confirmation (bypass with
--yes) - Maintains an undo log — reverses all file ops automatically if anything fails
- Self-validates after apply: if the migration graph gets worse, auto-reverts
--dry-run on any mutation command prints the full preview without writing.
CI Integration
Add to your pre-push hook or CI pipeline:
python manage.py migraid doctor --format json | jq '.[] | select(.severity == "error")'
Or fail CI on any ERROR-level issue:
python manage.py migraid doctor
(exits non-zero if any E0xx issues are found)
Contributing
See CONTRIBUTING.md.
License
Apache 2.0 — see LICENSE.
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_migraid-0.1.0b1.tar.gz.
File metadata
- Download URL: django_migraid-0.1.0b1.tar.gz
- Upload date:
- Size: 40.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd2ba8dafd07aeb574828c7a9977beefabda7684f90c53421aa62b7679db1121
|
|
| MD5 |
3d12f1648e6a45e0ef53ba2397b4d108
|
|
| BLAKE2b-256 |
21ca85e163a81ef004f308937671eb5efac30017fb8566595e87d89a0af18c20
|
File details
Details for the file django_migraid-0.1.0b1-py3-none-any.whl.
File metadata
- Download URL: django_migraid-0.1.0b1-py3-none-any.whl
- Upload date:
- Size: 27.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1400aa2dcfbc500ea46338f54ac735703be51ef94a3818def48ed31a8f5819d4
|
|
| MD5 |
2e6a252b246295af382e25f6f0fec52d
|
|
| BLAKE2b-256 |
843a8f2d1961a1fa80a5f9eff7fad90e058588c397e331a53058811d6e242356
|