Prisma "Drift detected" - Schema Not In Sync in CI
Prisma compared the database to its recorded migration history and found unexplained differences. Something changed the schema outside of migrations, so Prisma flags drift rather than guessing how to reconcile it. This is deterministic.
What this error means
prisma migrate dev/diff/status reports drift, summarizing added/removed columns or indexes. In CI it usually means the job pointed at a shared or pre-seeded database instead of a clean one.
Drift detected: Your database schema is not in sync with your migration history.
The following is a summary of the differences ...
[+] Added column `note` on table `orders`
[-] Removed index `orders_status_idx`Common causes
Shared/seeded database in CI
Pointing CI at a long-lived database that another branch or a seed script mutated diverges it from this branch's migration set.
Manual or db push change
Ad-hoc SQL or db push against the database makes its schema no longer match the migration history.
Applied migration edited
Changing the SQL of an already-applied migration makes the database and the migrations folder disagree.
How to fix it
Use a clean database per CI run
Apply the full migration history to a fresh, ephemeral database so no out-of-band change can cause drift.
services:
db:
image: postgres:16 # fresh DB each run; migrate deploy applies full historyCapture intentional drift as a migration
If the change is wanted, generate a migration recording it so history and schema agree.
npx prisma migrate diff \
--from-migrations ./prisma/migrations \
--to-schema-datasource ./prisma/schema.prisma \
--script > prisma/migrations/000_reconcile/migration.sqlHow to prevent it
- Run CI migrations against an ephemeral database, never a shared one.
- Apply all schema changes through migrations; treat applied migrations as immutable.
- This is deterministic - retrying against the same drifted database fails identically.