Runbook: Migration Failure Recovery¶
Use this runbook when schema migrations fail in development or release preparation.
Detection Signals¶
python manage.py migrateexits with error.- App startup fails with missing table or column errors.
- Divergent migration history between branches.
Recovery Flow¶
flowchart LR
A[Migration fails] --> B[Inspect migration state]
B --> C[Identify divergence or bad operation]
C --> D[Apply corrective migration strategy]
D --> E[Re-run migration]
E --> F[Run checks and targeted tests] Steps¶
- List migration state:
python manage.py showmigrations. - Inspect recent migration files and branch history.
- Resolve ordering/divergence issues via rebase or regenerated migration where appropriate.
- Re-run migrations.
- Validate with
python manage.py checkand targeted tests.
Validation¶
- Migration command completes without errors.
- App checks pass.
- Impacted module tests pass.
Data safety
Always take a backup before corrective operations that may alter migration history for shared environments.