Flyway "Detected failed migration" - Repair Needed in CI
A previous flyway migrate errored partway and recorded a failed entry in flyway_schema_history. Flyway blocks the next migrate until you remove that failed marker with repair - after fixing what made it fail.
What this error means
flyway migrate refuses to continue, reporting a detected failed migration to a specific version and pointing you at flyway repair. It is deterministic until the failed marker is cleared.
ERROR: Detected failed migration to version 3.2 (add orders index).
Please remove any half-completed changes then run repair to fix the
schema history.Common causes
A prior migration failed mid-apply
On a database without DDL transactions (e.g. MySQL), a migration can partially apply and then error, leaving a "failed" row in the history that blocks further migrates.
Half-completed changes left behind
The failed migration may have applied some statements. Those must be reconciled before repair so the next run starts from a known state.
How to fix it
Reconcile, repair, then migrate
Undo any half-applied changes from the failed migration, clear the failed marker with repair, then re-run.
# 1) manually undo half-applied changes if any
# 2) clear the failed history entry
flyway repair
# 3) re-run after fixing the migration SQL
flyway migrateFix the migration that failed
- Read the original error to see why the migration failed (bad SQL, constraint, timeout).
- Correct the migration so it can apply cleanly.
- Run migrations against a clean database in CI to confirm the fix.
How to prevent it
- Prefer databases/engines with transactional DDL so failures leave no partial state.
- Run
flyway validate/clean CI databases to catch failing migrations early. - Resolve a failed migration promptly instead of stacking new ones on top.