# db migrate (/docs/cli/db-migrate)

Apply pending Prisma ORM migrations.

Location: CLI > db migrate

`db migrate` applies pending on-disk migrations to advance the database. It walks every contract space (app and extensions) and applies migrations in canonical order: extensions alphabetically, then the app. It applies only the migrations that exist on disk and never generates new operations.

Use it from a controlled deployment step after reviewing migration packages.

## Usage

#### bun

```bash
bunx prisma db migrate --db "$DATABASE_URL"
```

#### pnpm

```bash
pnpm prisma db migrate --db "$DATABASE_URL"
```

#### yarn

```bash
yarn prisma db migrate --db "$DATABASE_URL"
```

#### npm

```bash
npx prisma db migrate --db "$DATABASE_URL"
```

## Options

| Option                 | What it does                                                                                                                                                           |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--db <url>`           | Connects to the database.                                                                                                                                              |
| `--to <contract>`      | Applies migrations up to a target contract (hash, prefix, ref name, migration directory name, `<dir>^`, or `./path`).                                                  |
| `--advance-ref <name>` | Advances the named [ref](/guides/migration-migration-ref) to the post-apply marker after success.                                                                      |
| `--show`               | Previews the migration route without applying (read-only).                                                                                                             |
| `--from <contract>`    | Sets the from-state for the `--show` preview: `@contract` (the emitted contract), `@db` (the database's current marker), a hash, a ref name, or a migration directory. |
| `--config <path>`      | Read this config file instead of `./prisma.config.ts`.                                                                                                                 |
| `--json`               | Prints a machine-readable result.                                                                                                                                      |

## Recommended flow

#### bun

```bash
bunx prisma migration status --db "$DATABASE_URL"
bunx prisma db migrate --db "$DATABASE_URL"
bunx prisma migration status --db "$DATABASE_URL"
bunx prisma db verify --db "$DATABASE_URL"
```

#### pnpm

```bash
pnpm prisma migration status --db "$DATABASE_URL"
pnpm prisma db migrate --db "$DATABASE_URL"
pnpm prisma migration status --db "$DATABASE_URL"
pnpm prisma db verify --db "$DATABASE_URL"
```

#### yarn

```bash
yarn prisma migration status --db "$DATABASE_URL"
yarn prisma db migrate --db "$DATABASE_URL"
yarn prisma migration status --db "$DATABASE_URL"
yarn prisma db verify --db "$DATABASE_URL"
```

#### npm

```bash
npx prisma migration status --db "$DATABASE_URL"
npx prisma db migrate --db "$DATABASE_URL"
npx prisma migration status --db "$DATABASE_URL"
npx prisma db verify --db "$DATABASE_URL"
```

Run `migration status` before and after applying migrations to see what changed.

## Previewing the route

`--show` prints the route `db migrate` would take without touching the database:

#### bun

```bash
bunx prisma db migrate --show
bunx prisma db migrate --show --from @contract --to production
```

#### pnpm

```bash
pnpm prisma db migrate --show
pnpm prisma db migrate --show --from @contract --to production
```

#### yarn

```bash
yarn prisma db migrate --show
yarn prisma db migrate --show --from @contract --to production
```

#### npm

```bash
npx prisma db migrate --show
npx prisma db migrate --show --from @contract --to production
```

## Applying to a target

If your project uses named [refs](/guides/migration-migration-ref), apply up to a target ref:

#### bun

```bash
bunx prisma db migrate --db "$DATABASE_URL" --to production
```

#### pnpm

```bash
pnpm prisma db migrate --db "$DATABASE_URL" --to production
```

#### yarn

```bash
yarn prisma db migrate --db "$DATABASE_URL" --to production
```

#### npm

```bash
npx prisma db migrate --db "$DATABASE_URL" --to production
```

Manage refs with [`migration ref`](/guides/migration-migration-ref).

## Related pages

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

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
