Prisma "Drift detected" schema out of sync in CI
Prisma compared the live database against the state implied by your migration history and they differ. prisma migrate dev reports drift and proposes a reset, which in CI shows up as an unexpected prompt or a destructive plan.
What this error means
prisma migrate dev prints "Drift detected: Your database schema is not in sync with your migration history" and lists the differences, then wants to reset the database.
Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences between the expected database schema...
[+] Added table `audit_log`Common causes
Schema changed outside of migrations
A table, column, or index was added or altered directly in the database (or by another tool), so the real schema no longer matches the migration history.
Using migrate dev against a shared or seeded database
migrate dev is for development and expects to own the database; pointing it at a pre-populated CI database makes it see the existing objects as drift.
How to fix it
Use migrate deploy in CI, not migrate dev
migrate deploy applies pending migrations without drift detection or resets, which is the correct command for CI and production.
npx prisma migrate deployReconcile real drift with a new migration
- Identify the out-of-band change from the drift summary.
- Either revert the manual change, or capture it in a new migration with
prisma migrate dev --name capture_drifton a development database. - Commit the new migration so history matches reality everywhere.
How to prevent it
- Reserve
migrate devfor local development and runmigrate deployin CI. - Never change the schema outside the migration workflow.
- Start CI migrations from a clean database so there is nothing to drift from.