Prisma error P3009 (Failed Migrations Found in Target Database) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.
Run `npx prisma migrate status` and look for any migration marked Failed. If that does not apply, inspect that migration's SQL and the real database state to decide what actually happened — the full checklist is below.
Error code: P3009
Official name: Failed Migrations Found in Target Database
Service: Prisma
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{details}
npx prisma migrate status
Lists each migration with Applied / Pending / Failed so you can target the exact one blocking progress.
npx prisma migrate resolve --rolled-back 20260801000000_add_index
npx prisma migrate deploy
Clears the failed state and lets the remaining pending migrations apply.
The recovery is always: find the failed migration, resolve it honestly, then continue.
npx prisma migrate status
npx prisma migrate resolve --applied 20260801000000_add_index
npx prisma migrate deploy
Make CI fail loudly on migrate status failures and require a human to run migrate resolve before the next deploy.
- run: npx prisma migrate deploy
- run: npx prisma migrate status
if: always()
Track failed migrations in your runbook: resolve --rolled-back for unapplied SQL, --applied for SQL that actually executed.
# runbook: prisma migrations
# failed at 20260801000000_add_index -> check _prisma_migrations,
# then: npx prisma migrate resolve --rolled-back 20260801000000_add_index
Most often this happens when an earlier migration failed to apply and was never resolved, so Prisma refuses to apply anything new, or when a teammate's migration was applied manually out of order, leaving the history inconsistent.
Run `npx prisma migrate status` and look for any migration marked Failed.
This page documents fixes for: prisma-cli, github-actions, nestjs.
Recommendations are editorial — DB Error Reference takes no payment or affiliate fees for tool listings.
This page is based on the official Prisma documentation linked below and adds practical troubleshooting guidance on top.