Prisma Error P3009: Failed Migrations Found in Target Database

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.

Error code P3009 Prisma Last verified 2026-08-19

Quick Answer

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

Error code: P3009
Official name: Failed Migrations Found in Target Database
Service: Prisma

What does this error mean?

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}

Common Causes

How to Fix

  1. Run `npx prisma migrate status` and look for any migration marked Failed
  2. Inspect that migration's SQL and the real database state to decide what actually happened
  3. If the SQL did run: `npx prisma migrate resolve --applied <name>`. If it did not: `--rolled-back <name>`
  4. Re-run `npx prisma migrate status` until every migration shows Applied or Pending
  5. Only then apply new migrations with `npx prisma migrate deploy`

Code Examples

Check which migration is failed bash
npx prisma migrate status

Lists each migration with Applied / Pending / Failed so you can target the exact one blocking progress.

Resolve and continue bash
npx prisma migrate resolve --rolled-back 20260801000000_add_index
npx prisma migrate deploy

Clears the failed state and lets the remaining pending migrations apply.

Framework-Specific Fixes

prisma-cli

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
github-actions

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()
nestjs

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

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P3009?

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.

How do I fix Prisma error P3009?

Run `npx prisma migrate status` and look for any migration marked Failed.

Which frameworks have documented fixes for error P3009?

This page documents fixes for: prisma-cli, github-actions, nestjs.

Official Sources

This page is based on the official Prisma documentation linked below and adds practical troubleshooting guidance on top.