Prisma Error P3018: A Migration Failed to Apply

Prisma error P3018 (A Migration Failed to Apply) explained: what it means, why it happens, and how to fix it — with copy-paste code examples.

Error code P3018 Prisma Last verified 2026-08-19

Quick Answer

Run `npx prisma migrate status` to see which migration is in a failed state and why. If that does not apply, open the failing migration folder and read its migration.sql against the actual database state — the full checklist is below.

Error Code

Error code: P3018
Official name: A Migration Failed to Apply
Service: Prisma

What does this error mean?

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve"Migration name: {migration_name}Database error code: {database_error_code}Database error:{database_error}

Common Causes

How to Fix

  1. Run `npx prisma migrate status` to see which migration is in a failed state and why
  2. Open the failing migration folder and read its migration.sql against the actual database state
  3. Fix either side: correct the database manually, or edit the migration SQL to match reality
  4. Tell Prisma the truth about the database state with `npx prisma migrate resolve --applied <name>` or `--rolled-back <name>`
  5. Re-run `npx prisma migrate dev` (or `migrate deploy`) to apply the remaining migrations

Code Examples

Check migration state bash
npx prisma migrate status

Shows every migration with a status of Applied / Pending / Failed so you know exactly which one is stuck.

Resolve a failed migration bash
# if the SQL actually ran against the DB despite the error:
npx prisma migrate resolve --applied 20260819000000_add_posts
# if it did not run:
npx prisma migrate resolve --rolled-back 20260819000000_add_posts

migrate resolve records the real state in _prisma_migrations without re-running SQL, unblocking the rest.

Framework-Specific Fixes

prisma-cli

Use migrate status + migrate resolve as the recovery loop: inspect, decide, mark, re-apply.

npx prisma migrate status
# if migration X actually applied despite the error:
npx prisma migrate resolve --applied 20260819000000_fix_fk
# if it did NOT apply:
npx prisma migrate resolve --rolled-back 20260819000000_fix_fk
github-actions

In CI, treat migrate deploy as the last step before smoke tests, and log migrate status on failure so a human can resolve.

- run: npx prisma migrate deploy
- run: npx prisma migrate status
  if: failure()
nestjs

Run migrations at deploy time (e.g. in a pre-start script), not on app boot, so a failed migration never takes down the process.

"start:prod": "prisma migrate deploy && node dist/main.js"

You Might Also Like

Frequently Asked Questions

Why am I seeing Prisma error P3018?

Most often this happens when the target database already contains a table with the same name but a different schema than the migration expects, or when a migration file references a column, constraint or enum that was manually dropped in the database.

How do I fix Prisma error P3018?

Run `npx prisma migrate status` to see which migration is in a failed state and why.

Which frameworks have documented fixes for error P3018?

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.