# diff (Prisma CLI v7) (/docs/cli/v7/migrate/diff) > For the complete Prisma documentation index, see [llms.txt](https://www.prisma.io/docs/llms.txt). A markdown version of any docs page is available by appending `.md` to its URL. Compare the database schema from two arbitrary sources Location: CLI > v7 > migrate > diff 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. > [!NOTE] > This command is only partially supported for [MongoDB](https://www.prisma.io/docs/orm/v7/core-concepts/supported-databases/mongodb). See options below for details. ## Usage [#usage] ```bash prisma migrate diff --from-... --to-... ``` 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](https://www.prisma.io/docs/orm/v7/reference/database-features). Differences in unsupported features (views, triggers, etc.) won't be shown. ## Prerequisites [#prerequisites] If using `--from-config-datasource` or `--to-config-datasource`, configure your database connection in `prisma.config.ts`: ```prisma file=schema.prisma generator client { provider = "prisma-client" output = "../generated/prisma" } datasource db { provider = "sqlite" } ``` ```typescript file=prisma.config.ts import { defineConfig, env } from "prisma/config"; export default defineConfig({ schema: "prisma/schema.prisma", migrations: { path: "prisma/migrations", }, datasource: { url: env("DATABASE_URL"), }, }); ``` ## Source types [#source-types] Both sources must use the same database provider. ### From options (one required) [#from-options-one-required] | 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+ | ### To options (one required) [#to-options-one-required] | 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+ | ### Other options [#other-options] | 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 | | > [!NOTE] > **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 [#examples] ### Compare database to schema [#compare-database-to-schema] Roll forward after a migration failed: #### bun ```bash bunx prisma migrate diff \ --from-config-datasource \ --to-schema=next_datamodel.prisma \ --script ``` #### pnpm ```bash pnpm prisma migrate diff \ --from-config-datasource \ --to-schema=next_datamodel.prisma \ --script ``` #### yarn ```bash yarn prisma migrate diff \ --from-config-datasource \ --to-schema=next_datamodel.prisma \ --script ``` #### npm ```bash npx prisma migrate diff \ --from-config-datasource \ --to-schema=next_datamodel.prisma \ --script ``` ### Compare schema to database [#compare-schema-to-database] #### bun ```bash bunx prisma migrate diff \ --from-schema=schema.prisma \ --to-config-datasource \ --script ``` #### pnpm ```bash pnpm prisma migrate diff \ --from-schema=schema.prisma \ --to-config-datasource \ --script ``` #### yarn ```bash yarn prisma migrate diff \ --from-schema=schema.prisma \ --to-config-datasource \ --script ``` #### npm ```bash npx prisma migrate diff \ --from-schema=schema.prisma \ --to-config-datasource \ --script ``` ### Compare migrations to database [#compare-migrations-to-database] Generate a migration for a hotfix already applied on production: #### bun ```bash bunx prisma migrate diff \ --from-migrations ./migrations \ --to-config-datasource \ --script ``` #### pnpm ```bash pnpm prisma migrate diff \ --from-migrations ./migrations \ --to-config-datasource \ --script ``` #### yarn ```bash yarn prisma migrate diff \ --from-migrations ./migrations \ --to-config-datasource \ --script ``` #### npm ```bash npx prisma migrate diff \ --from-migrations ./migrations \ --to-config-datasource \ --script ``` ### Pipe output to db execute [#pipe-output-to-db-execute] #### bun ```bash bunx prisma migrate diff \ --from-config-datasource \ --to-schema=schema.prisma \ --script | prisma db execute --stdin ``` #### pnpm ```bash pnpm prisma migrate diff \ --from-config-datasource \ --to-schema=schema.prisma \ --script | prisma db execute --stdin ``` #### yarn ```bash yarn prisma migrate diff \ --from-config-datasource \ --to-schema=schema.prisma \ --script | prisma db execute --stdin ``` #### npm ```bash npx prisma migrate diff \ --from-config-datasource \ --to-schema=schema.prisma \ --script | prisma db execute --stdin ``` ### Check if sources are in sync [#check-if-sources-are-in-sync] Exits with code 2 if changes are detected: #### bun ```bash bunx prisma migrate diff \ --exit-code \ --from-config-datasource \ --to-schema=schema.prisma ``` #### pnpm ```bash pnpm prisma migrate diff \ --exit-code \ --from-config-datasource \ --to-schema=schema.prisma ``` #### yarn ```bash yarn prisma migrate diff \ --exit-code \ --from-config-datasource \ --to-schema=schema.prisma ``` #### npm ```bash npx prisma migrate diff \ --exit-code \ --from-config-datasource \ --to-schema=schema.prisma ``` ## See also [#see-also] * [Migration troubleshooting in production](https://www.prisma.io/docs/orm/v7/prisma-migrate/workflows/patching-and-hotfixing#fixing-failed-migrations-with-migrate-diff-and-db-execute) ## Related pages - [`deploy`](https://www.prisma.io/docs/cli/v7/migrate/deploy): Apply pending migrations to update the database schema in production/staging - [`dev`](https://www.prisma.io/docs/cli/v7/migrate/dev): Create a migration from changes in Prisma schema, apply it to the database, and trigger generators - [`reset`](https://www.prisma.io/docs/cli/v7/migrate/reset): Reset your database and apply all migrations. All data will be lost - [`resolve`](https://www.prisma.io/docs/cli/v7/migrate/resolve): Resolve issues with database migrations in deployment databases - [`status`](https://www.prisma.io/docs/cli/v7/migrate/status): Check the status of your database migrations