🔧 Error Fixes

Fix: Prisma — migration failed / database schema drift


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 dev after changing schema.prisma
  • Never manually edit the database schema in development
  • Commit the prisma/migrations/ folder to Git

See also: Prisma cheat sheet | PostgreSQL cheat sheet