Django migrate keeps failing in CI with duplicate column/table errors — so I wrote a self-healing wrapper that detects the failing migration, fakes it, and retries
If you've run Django migrations on MySQL in CI long enough, you've seen this:
django.db.utils.OperationalError: (1060, "Duplicate column name 'some_field'")
Schema drift between environments, a migration applied manually, a botched rollback — whatever the cause, the pipeline is now broken and someone has to SSH in, figure out which migration to fake, run it manually, and retry.
I got tired of doing that so I wrote a wrapper around manage.py migrate that handles it automatically.
What it does:
Runs migrate normally
If it hits a duplicate column/table/key error (MySQL 1050, 1060, 1061, 1068, 1091) — parses the output to identify the failing migration, fakes it, and retries
If it hits InconsistentMigrationHistory — deletes the offending record from django_migrations and retries
Any other error — stops immediately so you don't mask real problems
Loops until all migrations are applied successfully or an unhandled error stops it
What it doesn't do:
Won't blindly fake everything — only fakes the specific migration that caused the error
Won't swallow unrecognised errors
MySQL only — relies on MySQL error codes
https://github.com/chiragJoshi24/Django-AutoMigrate/
Curious if others have hit this — how are you handling migration drift in CI?