apps/docs/content/docs/cli/migrate/diff.mdx
The prisma migrate diff command compares two database schema sources and outputs a description of the migration needed to transform the first into the second.
:::info
This command is only partially supported for MongoDB. See options below for details.
:::
prisma migrate diff --from-... <source1> --to-... <source2>
The output can be a human-readable summary (default) or an executable script.
:::warning
The migrate diff command can only compare database features supported by Prisma. Differences in unsupported features (views, triggers, etc.) won't be shown.
:::
If using --from-config-datasource or --to-config-datasource, configure your database connection in prisma.config.ts:
generator client {
provider = "prisma-client"
output = "../generated/prisma"
}
datasource db {
provider = "sqlite"
}
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("DATABASE_URL"),
},
});
Both sources must use the same database provider.
| Option | Description | Notes |
|---|---|---|
--from-empty | Assume the source is an empty data model | |
--from-schema | Path to a Prisma schema file | |
--from-migrations | Path to Prisma migrations directory | Not supported in MongoDB |
--from-config-datasource | Use datasource from Prisma config file | Prisma v7+ |
| Option | Description | Notes |
|---|---|---|
--to-empty | Assume the destination is an empty data model | |
--to-schema | Path to a Prisma schema file | |
--to-migrations | Path to Prisma migrations directory | Not supported in MongoDB |
--to-config-datasource | Use datasource from Prisma config file | Prisma v7+ |
| Option | Description | Notes |
|---|---|---|
--config | Custom path to your Prisma config file | |
--script | Output a SQL script instead of human-readable summary | Not supported in MongoDB |
-o, --output | Write to a file instead of stdout | Available since 5.12.1 |
--exit-code | Change exit code behavior: Empty=0, Error=1, Not empty=2 | Default: Success=0, Error=1 |
--help | Display help message |
:::info
Prisma v7 breaking change: The --from-url, --to-url, --from-schema-datasource, --to-schema-datasource, and --shadow-database-url options have been removed. Use --from-config-datasource and --to-config-datasource instead.
:::
Roll forward after a migration failed:
npx prisma migrate diff \
--from-config-datasource \
--to-schema=next_datamodel.prisma \
--script
npx prisma migrate diff \
--from-schema=schema.prisma \
--to-config-datasource \
--script
Generate a migration for a hotfix already applied on production:
npx prisma migrate diff \
--from-migrations ./migrations \
--to-config-datasource \
--script
npx prisma migrate diff \
--from-config-datasource \
--to-schema=schema.prisma \
--script | prisma db execute --stdin
Exits with code 2 if changes are detected:
npx prisma migrate diff \
--exit-code \
--from-config-datasource \
--to-schema=schema.prisma