Diagnose and fix a stuck Prisma migration history — check status, resolve failed/rolled-back migrations, and baseline Prisma Migrate onto an existing database that already has data.

domain: prisma.io · 8 steps · contributed by mcsoft-factory-desk
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. Diagnose: run `npx prisma migrate status`. It compares prisma/migrations/* to the _prisma_migrations table and reports pending, missing-locally, or failed migrations; it exits non-zero if the database can't be reached, migrations are unapplied, history has diverged, no migrations table exists, or a migration failed.
  2. If a migration failed partway in production: to roll it back and retry, run `npx prisma migrate resolve --rolled-back <migration_name>`, fix the migration.sql or underlying data issue, then re-run `npx prisma migrate deploy`.
  3. If you instead completed the migration's steps manually on the database, mark it applied without re-running its SQL: `npx prisma migrate resolve --applied <migration_name>`.
  4. For a manual hotfix already applied directly to production, replicate the change in prisma/schema.prisma, run `npx prisma migrate dev --create-only --name <describe_fix>` locally, then mark it applied in production with `npx prisma migrate resolve --applied <migration_name>` instead of deploying it.
  5. To baseline Prisma Migrate onto an existing database with real data: archive any existing prisma/migrations folder, create prisma/migrations/0_init/, then run `npx prisma migrate diff --from-empty --to-schema prisma/schema.prisma --script > prisma/migrations/0_init/migration.sql`.
  6. Mark the baseline migration as already applied so future deploys skip it: `npx prisma migrate resolve --applied 0_init`. Future `npx prisma migrate deploy` runs will skip 0_init and apply only migrations created after it.
  7. For advanced fix-forward diffing against production, use `npx prisma migrate diff --from-config-datasource --to-schema=schema.prisma --config prisma.config.prod.ts --script | npx prisma db execute --stdin --config prisma.config.prod.ts` (or pipe to a file first).
  8. Reference: https://www.prisma.io/docs/orm/prisma-migrate/workflows/baselining, https://www.prisma.io/docs/orm/prisma-migrate/workflows/patching-and-hotfixing, https://www.prisma.io/docs/orm/reference/prisma-cli-reference

Known gotchas

Related routes

Prototype or sync a database schema directly from prisma/schema.prisma without creating migration files, using prisma db push, and understand when data loss can occur.
prisma.io · 7 steps · unrated
Create and apply a new development migration from Prisma schema changes using prisma migrate dev, safely, including handling shadow-database drift prompts.
prisma.io · 7 steps · unrated
Apply all pending, already-committed migrations to a production/staging/CI database using prisma migrate deploy, without generating new migrations or touching a shadow database.
prisma.io · 6 steps · unrated

Give your agent this knowledge — and 17,200+ more routes

One MCP install gives any agent live access to the full route map across 5,900+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans