# migration plan (/docs/cli/migration-plan)

> 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.

Plan an on-disk migration from Prisma ORM contract changes.

Location: CLI > migration plan

`migration plan` compares the emitted contract against a starting contract and produces a new migration package with the required operations.

The starting contract is whatever `--from` names, or the [ref](https://www.prisma.io/docs/cli/migration-ref) named `db` when `--from` is absent.

With neither, what happens depends on the migrations already on disk:

* **`migrations/app/` is empty.** The plan starts from an empty database and contains the full `CREATE` operations for the whole contract. This is the first migration in a new project. The command says so under its summary (`No db ref set — planning from an empty database`), and `--json` output carries `fromDefaulted: true`, so a plan that recreates a database you already have is easy to spot. If a database already exists, run `db init`, `db update`, or `db sign` first.
* **Migrations already exist.** The command refuses with `MIGRATION.PLAN_ORIGIN_UNKNOWN` rather than write a full-create package that no real database could apply. The error names the three exits: `migration ref set db <contract>` to point the ref at the state your database is on, `--from <ref>` to name the origin for this one plan, or `--from @empty` to plan from an empty database deliberately.

Keep the `db` ref current and you never see the refusal. [`db init`](https://www.prisma.io/docs/cli/db-init) and [`db update`](https://www.prisma.io/docs/cli/db-update) advance it for you when you run them without `--db`; with `--db` you have to add `--advance-ref db`. [`db sign`](https://www.prisma.io/docs/cli/db-sign) advances it whenever it signs, `--db` or not. [`db migrate`](https://www.prisma.io/docs/cli/db-migrate) advances nothing unless you pass `--advance-ref db`.

### The automatic baseline [#the-automatic-baseline]

When `migrations/app/` is empty and the `db` ref points at a contract whose snapshot is stored under `migrations/snapshots/`, one `migration plan` run writes a baseline package from nothing to the ref's contract and, when your emitted contract differs from the ref's, a second package with the delta. Expect one or two new directories in `git status`. The baseline is never replayed against a database that already carries a marker, because the runner starts from the marker and only applies edges past it.

The command is offline. It does not need a database connection.

## Usage [#usage]

  

#### bun

```bash
bunx prisma@latest migration plan --name add_users_table
```

#### pnpm

```bash
pnpm dlx prisma@latest migration plan --name add_users_table
```

#### yarn

```bash
yarn dlx prisma@latest migration plan --name add_users_table
```

#### npm

```bash
npx prisma@latest migration plan --name add_users_table
```

## Options [#options]

| Option              | What it does                                                                                                                                                                                                                          |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--name <slug>`     | Sets the migration directory name suffix.                                                                                                                                                                                             |
| `--from <contract>` | Uses a specific starting contract reference (hash, prefix, ref name, migration directory name, `<dir>^`, `./path`, or `@empty`) instead of the `db` ref. `migration plan` is offline, so `@db` and `@contract` are not accepted here. |
| `--to <contract>`   | Sets the destination contract reference. Defaults to the emitted contract. Same grammar as `--from`, except that `@empty` is refused as a destination.                                                                                |
| `--config <path>`   | Read this config file instead of `./prisma.config.ts`.                                                                                                                                                                                |
| `--json`            | Prints a machine-readable result.                                                                                                                                                                                                     |

## Recommended flow [#recommended-flow]

  

#### bun

```bash
bunx prisma@latest contract emit
bunx prisma@latest migration plan --name add_users_table
bunx prisma@latest migration show <migration-dir>
```

#### pnpm

```bash
pnpm dlx prisma@latest contract emit
pnpm dlx prisma@latest migration plan --name add_users_table
pnpm dlx prisma@latest migration show <migration-dir>
```

#### yarn

```bash
yarn dlx prisma@latest contract emit
yarn dlx prisma@latest migration plan --name add_users_table
yarn dlx prisma@latest migration show <migration-dir>
```

#### npm

```bash
npx prisma@latest contract emit
npx prisma@latest migration plan --name add_users_table
npx prisma@latest migration show <migration-dir>
```

Review the generated migration package before applying it with [`db migrate`](https://www.prisma.io/docs/cli/db-migrate).

## Planning a rollback [#planning-a-rollback]

Because `--to` accepts `<dir>^` (the source contract of a migration), you can plan a migration that walks back a change:

  

#### bun

```bash
bunx prisma@latest migration plan --to <migration-dir>^ --name rollback
```

#### pnpm

```bash
pnpm dlx prisma@latest migration plan --to <migration-dir>^ --name rollback
```

#### yarn

```bash
yarn dlx prisma@latest migration plan --to <migration-dir>^ --name rollback
```

#### npm

```bash
npx prisma@latest migration plan --to <migration-dir>^ --name rollback
```

## When to use migration plan [#when-to-use-migration-plan]

Use `migration plan` when your team wants database changes reviewed in version control. For local prototypes where review is not needed, [`db update`](https://www.prisma.io/docs/cli/db-update) is usually faster.

If the generated migration is not the migration you want, use [`migration new`](https://www.prisma.io/docs/cli/migration-new) and author the migration manually.

## Related pages

- [`auth`](https://www.prisma.io/docs/cli/auth): Sign in to your Prisma account from the CLI, sign out, and manage workspace sessions.
- [`branch`](https://www.prisma.io/docs/cli/branch): List platform branches for a project.
- [`bucket`](https://www.prisma.io/docs/cli/bucket): Create and manage object-store buckets.
- [`Configuration`](https://www.prisma.io/docs/cli/configuration): Configure Prisma ORM CLI commands with prisma.config.ts and global flags.
- [`contract emit`](https://www.prisma.io/docs/cli/contract-emit): Emit Prisma ORM contract artifacts.