Prisma error: Drift detected — your database schema is not in sync with your migration history
Someone (or something) changed the database schema directly — outside of Prisma's migration files — so the actual database no longer matches what Prisma's migration history says it should look like. You need to either reconcile the drift manually or reset the dev database if the data is disposable.
What causes this error
Prisma tracks schema changes through migration files in prisma/migrations. If a table or column was added, dropped, or altered directly in the database (via a GUI tool, a manual SQL script, or a different tool entirely) without going through prisma migrate, Prisma detects the mismatch and refuses to apply further migrations blindly, since it can't safely reconcile the difference.
The Fix
# If this is a local/dev database and the data is disposable:
npx prisma migrate reset
# If the data matters, inspect the actual drift first:
npx prisma migrate diff \
--from-migrations ./prisma/migrations \
--to-schema-datamodel ./prisma/schema.prisma \
--scriptThe diff output shows exactly what's different, so you can write a manual migration that reconciles it instead of guessing.
Common causes / variations
- Making a quick manual change directly in a database GUI (TablePlus, pgAdmin) and forgetting to create a matching migration
- Two team members' local databases diverging because one ran a migration the other didn't
- Restoring a database backup from a point that predates the latest migrations
Related errors
See also: PrismaClientInitializationError, relation does not exist.
Comments
Loading comments...