Skip to content
Latchkey

Prisma "P3009: migrate found failed migrations in the target database" in CI

P3009 means the _prisma_migrations table records a migration that started but did not finish. To avoid applying migrations on top of a broken state, migrate deploy stops until you resolve the failed entry.

What this error means

migrate deploy fails immediately with "P3009: migrate found failed migrations in the target database" and names the migration that is marked failed.

Prisma
Error: P3009 migrate found failed migrations in the target database, new migrations will not be applied.
The `20260601120000_add_orders` migration started at ... failed

Common causes

A previous migration failed partway

An earlier deploy applied part of a migration then failed, leaving a failed record that blocks further migrations.

A shared database left in a bad state

A prior job or environment failed a migration on the same database, and later jobs inherit the blocked state.

How to fix it

Resolve the failed migration

  1. Inspect what the failed migration did to the schema.
  2. Mark it rolled-back or applied with prisma migrate resolve.
  3. Re-run prisma migrate deploy.
Terminal
npx prisma migrate resolve --rolled-back 20260601120000_add_orders
npx prisma migrate deploy

Reset a disposable CI database

If the database is ephemeral in CI, resetting it clears the failed state so migrations apply from scratch.

Terminal
npx prisma migrate reset --force

How to prevent it

  • Make CI migrations idempotent and test them before merge.
  • Use a fresh ephemeral database per CI run where possible.
  • Resolve failed migrations promptly so shared DBs are not blocked.

Related guides

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