How to fix P3011: Migration cannot be rolled back because it was never applied in Prisma

PrismaBEGINNERMEDIUMUpdated Dec 22, 2025· 116 views

Prisma throws P3011 when you try to mark a migration as rolled back even though it never ran — the CLI only allows `migrate resolve --rolled-back` on migrations that failed during execution.

Quick fix

Fixes P3011: Migration cannot be rolled back because it was never applied

SELECT migration_name, applied_steps_count, finished_at, status, failed_at
FROM "_prisma_migrations"
WHERE migration_name = '20220714121901_add_profile';
  1. Check the migration state before resolving
  2. Delete any un-applied migration directories instead of rolling them back
  3. Only mark failed migrations as rolled back
  4. Roll forward instead of trying to revert successful migrations
prisma — error
SELECT migration_name, applied_steps_count, finished_at, status, failed_at
FROM "_prisma_migrations"
WHERE migration_name = '20220714121901_add_profile';
P3011: Migration cannot be rolled back because it was never applied

What this error means

P3011 means that Prisma already knows this migration was never applied, so there is nothing to revert. The `migrate resolve --rolled-back <name>` command is only valid for migrations that ran but stopped with an error; it toggles the `_prisma_migrations` record from `failed` to `rolledBack`. If the migration never reached the database (either it was newly created or you pointed at the wrong database), Prisma refuses the rollback because it would leave the migration history inconsistent. Use `prisma migrate status` or query `_prisma_migrations` to see whether the migration has `applied_steps_count > 0` or a `failed_at` timestamp before you attempt to resolve it.

Typical symptoms

  • PrismaClientKnownRequestError with code P3011 and message “Migration <name> cannot be rolled back because it was never applied to the database.”
  • Running `npx prisma migrate resolve --rolled-back <name>` fails even though the migration directory still exists.
  • `npx prisma migrate status` shows the target migration under “Pending migrations” rather than “Failed migrations.”
  • There is no `failed_at` or `status` flag set in the `_prisma_migrations` row, yet you are trying to resolve it.
  • Deploy scripts choke on P3011 after attempting to undo a migration that has not been logged as applied (often because the wrong DATABASE_URL was used).

Common causes

  1. Invoking `migrate resolve --rolled-back` for a migration that was never applied (the row in `_prisma_migrations` lacks an `applied_at` value).
  2. Pointing Prisma at the wrong database/environment so the CLI cannot find the migration record it thinks it created.
  3. Misunderstanding “rolled-back” as a shortcut to undo a schema change that succeeded; Prisma only flips `failed` migrations into a rolled-back state.
  4. Discarding a migration folder without updating the history table, then trying to mark it as rolled back.
  5. Attempting to revert a previously applied migration without creating a compensating migration.

How to fix "P3011: Migration cannot be rolled back because it was never applied"

1Check the migration state before resolving

Ask Prisma about the status of the offending migration with npx prisma migrate status --schema prisma/schema.prisma. If you prefer SQL, query the migrations table directly:

sql
SELECT migration_name, applied_steps_count, finished_at, status, failed_at
FROM "_prisma_migrations"
WHERE migration_name = '20220714121901_add_profile';

If applied_steps_count is 0 and failed_at is null, the migration never touched the database and cannot be marked as rolled back.

2Delete any un-applied migration directories instead of rolling them back

If your migration was created locally but never applied, there is no “rollback” to run. Delete the folder inside prisma/migrations/<timestamp>_name, then rerun npx prisma migrate dev (or generate a fresh migration with npx prisma migrate diff/npx prisma migrate dev --name <new>). This keeps the history in sync without touching _prisma_migrations.

3Only mark failed migrations as rolled back

When a migration fails to apply, _prisma_migrations records failed_at. That is the only time prisma migrate resolve --rolled-back <name> should be used. Double-check the row before running the command, then execute:

bash
npx prisma migrate resolve --rolled-back 20220714121901_add_profile

If the migration is still marked as failed, this command clears the failure and allows the next deployments to start from scratch.

4Roll forward instead of trying to revert successful migrations

Prisma does not generate automatic down migrations. To undo a schema change that already succeeded, author a new migration that puts the schema back in the desired state (for example, drop the column or revert the default). Alternatively, use npx prisma migrate diff --from-schema-datasource --to-schema-datamodel --script > rollback.sql to craft manual SQL and update _prisma_migrations rows so the CLI stays aware of the history.

Advanced notes

The migrate resolve command is documented to operate on failed migrations only, so it will always throw P3011 when the history table records no failure. Production troubleshooting guides still recommend resolving failed migrations by marking them as rolled back so you can reapply them, but the migration must actually have failed first. If you keep hitting P3011 after confirming the row exists, verify that DATABASE_URL points to the environment you expect; running the command against the wrong database often looks like an un-applied migration.

Frequently asked questions

What does "P3011: Migration cannot be rolled back because it was never applied" mean?
P3011 means that Prisma already knows this migration was never applied, so there is nothing to revert. The migrate resolve --rolled-back <name> command is only valid for migrations that ran but stopped with an error; it toggles the _prisma_migrations record from failed to rolledBack. If the migration never reached the database (either it was newly created or you pointed at the wrong database), Prisma refuses the rollback because it would leave the migration history inconsistent.
How do I fix "P3011: Migration cannot be rolled back because it was never applied"?
Prisma throws P3011 when you try to mark a migration as rolled back even though it never ran — the CLI only allows migrate resolve --rolled-back on migrations that failed during execution.
What causes "P3011: Migration cannot be rolled back because it was never applied"?
Invoking migrate resolve --rolled-back for a migration that was never applied (the row in _prisma_migrations lacks an applied_at value). Pointing Prisma at the wrong database/environment so the CLI cannot find the migration record it thinks it created. Misunderstanding “rolled-back” as a shortcut to undo a schema change that succeeded; Prisma only flips failed migrations into a rolled-back state.
Is the "P3011: Migration cannot be rolled back because it was never applied" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading