| name | django-migration-check |
| description | Check and validate Django migrations for safety and correctness before deployment |
| disable-model-invocation | true |
| allowed-tools | Read, Bash, Grep, Glob |
Django Migration Safety Check
Run this checklist on every migration before committing. Execute each step.
Step 1: Identify New Migrations
git status --short | grep migrations
python manage.py showmigrations --list | grep "\[ \]"
Step 2: Review Migration SQL
For each new migration, inspect the generated SQL:
python manage.py sqlmigrate <app_name> <migration_number>
Check the SQL for:
ALTER TABLE ... ADD COLUMN ... NOT NULL without a DEFAULT — dangerous on large tables
CREATE INDEX without CONCURRENTLY on large tables — locks the table
ALTER TABLE ... DROP COLUMN — data loss, ensure multi-step deploy
ALTER TABLE ... ALTER COLUMN TYPE — may rewrite the table
ALTER TABLE ... RENAME COLUMN — breaks running code during deploy
Step 3: Safety Checklist
Adding a New Field
Removing a Field
Renaming a Field
Adding an Index
Adding a Constraint
Data Migration (RunPython)
Removing a Model
Step 4: Test Migrations
Forward Test
python manage.py migrate <app_name> <new_migration>
python manage.py check
pytest <app_name>/tests/ -x
Backward Test
python manage.py migrate <app_name> <previous_migration>
python manage.py check
Full Reset Test
python manage.py migrate <app_name> zero
python manage.py migrate <app_name>
Step 5: Pre-Deployment Checklist
Step 6: Report Format
## Migration Review: <app_name>/<migration_file>
**Operations:**
- AddField: `status` to `Order` (CharField, db_default="draft") ✅ Safe
- AddIndex: `orders_order_status_idx` on `Order.status` ⚠️ Use CONCURRENTLY for large tables
**Risk Level:** Low / Medium / High
**Requires Multi-Step Deploy:** Yes / No
**Estimated Lock Time:** None / <1s / >1s (investigate)
**Backward Compatible:** Yes / No
**Recommendations:**
1. ...