Error: P3006 β Migration failed to apply cleanly to the shadow database.
or
Drift detected: Your database schema is not in sync with your migration history.
Your Prisma schema, migration history, and actual database are out of sync.
Fix 1: Reset the database (development only)
npx prisma migrate reset
This drops the database, re-runs all migrations, and re-seeds. Only use in development β this deletes all data.
Fix 2: Create a new migration from current state
If you changed the schema and havenβt migrated yet:
npx prisma migrate dev --name describe_your_change
This generates a new migration SQL file and applies it.
Fix 3: Mark a migration as applied
If you applied changes manually and need Prisma to catch up:
npx prisma migrate resolve --applied 20240101000000_migration_name
Fix 4: Fix shadow database issues
The shadow database error often means your migration SQL has issues. Check the latest migration file in prisma/migrations/ and fix the SQL, then:
npx prisma migrate dev
Fix 5: Start fresh with baseline
If migrations are hopelessly broken:
# 1. Delete the migrations folder
rm -rf prisma/migrations
# 2. Create a fresh baseline from current schema
npx prisma migrate dev --name init
# 3. In production, mark it as already applied
npx prisma migrate resolve --applied 20240101000000_init
Fix 6: Generate client after schema changes
If your types are out of date:
npx prisma generate
Prevention
-
Always run
npx prisma migrate devafter changingschema.prisma -
Never manually edit the database schema in development
-
Commit the
prisma/migrations/folder to Git -
Run the migration against an ephemeral database in CI.
-
Keep production data recovery separate from development reset commands.
-
Make migrations backward-compatible when old AI workers and new API versions overlap.
-
Record which application release applied each production migration.
For AI backends, preserve agent jobs, tool approvals, conversation state and audit records during migration. A reset that is acceptable locally is not a production drift strategy.
See also: Prisma cheat sheet | PostgreSQL cheat sheet
Related: PostgreSQL Cheat Sheet