Prisma "P3009: migrate found failed migrations" in CI
Prisma's _prisma_migrations table has a migration marked failed from an earlier run. To protect a possibly-inconsistent database, migrate deploy stops and refuses to apply anything until that record is resolved. This is deterministic.
What this error means
prisma migrate deploy refuses to apply migrations and reports P3009, naming the migration that previously failed. Every run stops at the same recorded failure until you resolve it.
Error: P3009
migrate found failed migrations in the target database, new migrations
will not be applied. Read more about how to resolve migration issues
in a production database: https://pris.ly/d/migrate-resolve
The `20240115_add_orders` migration started at ... failedCommon causes
A prior migration failed and was never resolved
An earlier deploy partially applied a migration that errored (bad SQL, timeout, interrupted run). Prisma recorded it as failed and now blocks further deploys.
Database and migration record disagree
The failed migration may have applied some statements but not others, leaving an in-between state Prisma will not build on top of.
How to fix it
Resolve the failed migration
Decide whether the change is present, then mark the record accordingly.
# the changes were undone / never applied
npx prisma migrate resolve --rolled-back 20240115_add_orders
# the changes are fully present already
npx prisma migrate resolve --applied 20240115_add_ordersUse a clean database per CI run
- Run migrations against a fresh, ephemeral database so no failed record persists between runs.
- Apply the full history with
migrate deployfrom empty. - Reserve
resolvefor genuine production recovery.
How to prevent it
- Run
migrate deploy(nevermigrate dev) in CI so failures are explicit. - Use an ephemeral database per run so a failed record never lingers.
- This is deterministic - retrying without resolving the record fails identically.