Skip to content
Latchkey

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.

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

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

Use a clean database per CI run

  1. Run migrations against a fresh, ephemeral database so no failed record persists between runs.
  2. Apply the full history with migrate deploy from empty.
  3. Reserve resolve for genuine production recovery.

How to prevent it

  • Run migrate deploy (never migrate 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.

Frequently asked questions

What causes ""P3009: migrate found failed migrations""?
An earlier deploy partially applied a migration that errored (bad SQL, timeout, interrupted run). Prisma recorded it as failed and now blocks further deploys.
How do I fix "P3009: migrate found failed migrations"?
Decide whether the change is present, then mark the record accordingly.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card