In Prisma 7, how do `prisma migrate dev` and `prisma migrate deploy` differ, and why should only `migrate deploy` run against production?
answer
- authoring versus applying
- shadow database and drift
- deploy reads only committed files
- a reset is never acceptable in production
basics
~20 sPrisma's migrate dev authors migrations: it checks for drift in a shadow database, generates SQL from schema changes and may require a reset. Migrate deploy only applies committed, pending migration files, never generates or resets, so it is the production command.
solid answer
~50 s`prisma migrate dev` is a development command. It replays the migration history in a temporary shadow database to detect drift or an edited migration, applies pending migrations, then diffs the history against the Prisma schema, writes a new migration and applies it. When it finds drift it says the database must be reset and points you to `prisma migrate reset`. `prisma migrate deploy` reads the migration folders and `_prisma_migrations`, stops if a migration is recorded as failed, and applies only the pending files. It never reads the schema to invent SQL, uses no shadow database, does no drift check and never resets. That is why production gets `migrate deploy`: it runs exactly the reviewed files, needs no right to create databases and has no branch that ends in dropping data. In Prisma 7 neither command runs `prisma generate` or the seed.
code
bash · 6 lines# Developer machine: author and apply a migration, then regenerate the client
npx prisma migrate dev --name add_order_status
npx prisma generate
# Release pipeline: apply committed migrations only
npx prisma migrate deploygo deeper
Remember the rule: migrate dev on your own machine, migrate deploy everywhere else, and migrate reset only on a database you are happy to lose.
Walk through migrate dev's steps, including the shadow database and drift check, and list exactly what migrate deploy reads, applies, warns about and refuses.
Explain the production risks migrate dev carries: invented SQL, a reset path, extra privileges, prompts. Then say what deploy cannot see, and how you would surface drift before a release.
Decide where the authoring and applying steps run for your team, who can run deploy against production, and what check guards against drift that deploy will never see.
## Two commands, two jobs Prisma Migrate splits its work between an **authoring** command and an **applying** command. `prisma migrate dev` turns changes in the Prisma schema into new migration files on a developer's machine. `prisma migrate deploy` takes the committed migration files and applies the ones a database has not seen yet. Mixing them up is the classic way a migration flow that works locally rewrites a production database. ## What `migrate dev` does 1. Validates the schema and creates the development database if it does not exist. 2. Uses a **shadow database**, a second database it creates and drops on each run (or resets, if you configure a dedicated one), to replay the existing migration history and compare the result with the development database. A mismatch is **drift**; an applied migration whose file was edited or deleted is a **history conflict**. 3. On drift or a conflict it reports what differs, says the database must be reset, suggests `prisma migrate reset` and exits. In Prisma 7.10 it does not drop anything on its own. 4. Applies pending migration files, such as ones a teammate committed. 5. Diffs the history's end state against the Prisma schema, warns about data loss and asks for confirmation (in a non-interactive shell it refuses and tells you to use `migrate deploy`), then writes a new migration folder and applies it. Because it creates the shadow database, the database user needs the right to create databases; on PostgreSQL that means `CREATEDB` or superuser. Where that is impossible you point it at a dedicated database through `shadowDatabaseUrl` in the Prisma config file. ## What `migrate deploy` does - Lists the migration folders in lexicographic order and reads the rows in `_prisma_migrations`. - Stops with `P3009` if any migration is recorded as failed. - Prints a warning when an applied migration's file was modified since it ran, and carries on. - Applies each pending migration and records it; creates the database if it does not exist. - Does **not** detect drift, use a shadow database, generate new migrations, reset the database or run `prisma generate`. Both commands, and `prisma migrate resolve`, take an **advisory lock** on the database so that two pipelines started in quick succession cannot apply migrations at the same time. The lock wait times out after 10 seconds (not configurable), and the command then has to be run again. ## Side by side | | `prisma migrate dev` | `prisma migrate deploy` | |---|---|---| | Job | create and apply migrations while developing | apply committed migrations | | Reads the Prisma schema to generate SQL | yes | no, only migration files | | Shadow database | required | not used | | Drift detection | yes | no | | Can end in "reset the database" | yes | never | | Prompts for confirmation | yes | no | | Runs `prisma generate` or the seed in Prisma 7 | no | no | ## Why production gets only `migrate deploy` - **It never invents SQL.** Deploy executes exactly the files that were reviewed and committed. `migrate dev` diffs the schema against the history wherever it runs, and could write and apply a migration nobody has reviewed. - **It never needs a reset.** A drift or history check that fails ends, in `migrate dev`, with "reset the database". On production that is data loss. Deploy has no such branch. - **It needs fewer privileges.** With no shadow database, the production user needs no right to create or drop databases. - **It runs unattended.** It fits a pipeline step, while `migrate dev` is built around prompts. The trade-off is that deploy trusts `_prisma_migrations`. It will not notice a column someone added by hand; that surfaces later as a failed migration. Teams that want an early warning run `prisma migrate diff` against production as a separate step. ## And `migrate reset` `prisma migrate reset` drops the database (or the schema, on PostgreSQL), recreates it and applies every migration. It asks for confirmation unless `--force` is passed, and in Prisma 7 it no longer runs the seed script. Like `migrate dev`, it belongs on development databases only.
- Does `prisma migrate deploy` notice a column someone added to production by hand?No. Deploy compares migration folders with `_prisma_migrations` rows and never inspects the schema itself, so drift goes unnoticed until a later migration collides with it and fails. Drift detection lives in `migrate dev`, through the shadow database; for production you run `prisma migrate diff` as a separate check.
- What does `migrate deploy` do when an already-applied migration file has been edited?It prints `WARNING The following migrations have been modified since they were applied:` with the names, then applies any pending migrations. It does not re-run the edited file, so databases that already ran the original keep the original's effect.
- Why does `migrate dev` fail with a permission error on a hosted database that `migrate deploy` handles fine?`migrate dev` creates and drops a shadow database on each run, so its user needs the right to create databases; on PostgreSQL that is `CREATEDB` or superuser. Deploy uses no shadow database. If the host forbids creating databases, create one yourself and set `shadowDatabaseUrl` in the Prisma config file.
- migrate deploy checks production for drift before applying anything
- Running migrate dev in production is fine if nobody edits the schema
- migrate deploy generates a migration when the schema has changed
- Production needs a shadow database for migrate deploy
- In Prisma 7, migrate dev still runs generate and the seed afterwards
Assumes Prisma 7, where migrate dev no longer runs prisma generate or the seed and migrate reset no longer seeds; the dev/deploy split itself is older.