How to generate a Prisma migration file when the database schema and migration history drift apart.
Sometimes your database already contains schema changes that are missing from your Prisma migration files.
In these situations:
You want Prisma migrations to catch up with the current database state.
Instead of recreating everything from scratch, you can generate a migration representing the difference between:
schema.prismamkdir prisma/migrations/20260515000000_add_file_type
npx prisma migrate diff \
--from-config-datasource \
--to-schema prisma/schema.prisma \
--script > prisma/migrations/20260515000000_add_file_type/migration.sql
This generates SQL representing the difference between:
Always inspect the generated SQL before applying or marking migrations.
Prisma will generate SQL based purely on detected differences.
So if your schema contains accidental changes, those will also appear in the generated migration.
prisma migrate diff is one of Prisma's most useful recovery tools.
Especially when working with existing databases or repairing migration drift.
Understanding the difference between:
makes Prisma migrations much easier to reason about.