Skip to content
Latchkey

Prisma "P3009: migrate found failed migrations" in CI

Prisma’s _prisma_migrations table has a migration marked as failed from an earlier run. To protect a possibly-inconsistent database, migrate deploy stops and asks you to resolve that record before continuing.

What this error means

prisma migrate deploy refuses to apply anything and reports P3009, naming the migration that previously failed. It is deterministic: every run stops at the same recorded failure until you mark it resolved.

prisma output
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 ... failed

Common causes

A prior migration failed and was never resolved

An earlier migrate deploy partially applied a migration that errored (bad SQL, timeout, interrupted run). Prisma recorded it as failed and now blocks further deploys.

Database state and migration record disagree

The failed migration may have applied some statements but not others, so the database is in an in-between state Prisma will not silently build on top of.

How to fix it

Inspect what actually applied, then resolve

Decide whether the failed migration’s changes are present. If you reverted them (or they never applied), mark it rolled back; if they are fully present, mark it applied.

Terminal
# 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_orders

Fix the underlying migration before redeploying

  1. Read the original failure to understand why the migration errored.
  2. Correct the migration SQL (or the data condition that broke it).
  3. Re-run prisma migrate deploy after the failed record is resolved.

How to prevent it

  • Run migrate deploy (never migrate dev) in CI/production so failures are explicit.
  • Apply migrations transactionally where the database supports it, so a failure leaves no partial state.
  • Resolve a failed migration promptly instead of stacking new ones on top.

Frequently asked questions

Can I just delete the row from _prisma_migrations?
Avoid it. migrate resolve is the supported path and keeps the history consistent. Hand-editing the table risks a mismatch between recorded history and actual schema.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →