diff

Compare the database schema from two arbitrary sources

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.

This command is only partially supported for MongoDB. See options below for details.

Usage

prisma migrate diff --from-... <source1> --to-... <source2>

The output can be a human-readable summary (default) or an executable script.

The migrate diff command can only compare database features supported by Prisma. Differences in unsupported features (views, triggers, etc.) won't be shown.

Prerequisites

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"),
  },
});

Source types

Both sources must use the same database provider.

From options (one required)

OptionDescriptionNotes
--from-emptyAssume the source is an empty data model
--from-schemaPath to a Prisma schema file
--from-migrationsPath to Prisma migrations directoryNot supported in MongoDB
--from-config-datasourceUse datasource from Prisma config filePrisma v7+

To options (one required)

OptionDescriptionNotes
--to-emptyAssume the destination is an empty data model
--to-schemaPath to a Prisma schema file
--to-migrationsPath to Prisma migrations directoryNot supported in MongoDB
--to-config-datasourceUse datasource from Prisma config filePrisma v7+

Other options

OptionDescriptionNotes
--configCustom path to your Prisma config file
--scriptOutput a SQL script instead of human-readable summaryNot supported in MongoDB
-o, --outputWrite to a file instead of stdoutAvailable since 5.12.1
--exit-codeChange exit code behavior: Empty=0, Error=1, Not empty=2Default: Success=0, Error=1
--helpDisplay help message

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.

Examples

Compare database to schema

Roll forward after a migration failed:

npx prisma migrate diff \
  --from-config-datasource \
  --to-schema=next_datamodel.prisma \
  --script

Compare schema to database

npx prisma migrate diff \
  --from-schema=schema.prisma \
  --to-config-datasource \
  --script

Compare migrations to database

Generate a migration for a hotfix already applied on production:

npx prisma migrate diff \
  --from-migrations ./migrations \
  --to-config-datasource \
  --script

Pipe output to db execute

npx prisma migrate diff \
  --from-config-datasource \
  --to-schema=schema.prisma \
  --script | prisma db execute --stdin

Check if sources are in sync

Exits with code 2 if changes are detected:

npx prisma migrate diff \
  --exit-code \
  --from-config-datasource \
  --to-schema=schema.prisma

See also

On this page