Using Prisma Migrate: apply schema changes from development to production
Prisma Migrate records changes to `schema.prisma` as SQL migration files and applies that history to databases in different environments. During development, `migrate dev` creates and applies a migration. In production, use `migrate deploy` to apply reviewed, version-controlled migrations instead. Review generated SQL for data loss, renames, and the actual target before applying it.
Using Prisma Migrate: apply schema changes from development to production
Prisma Migrate records changes to schema.prisma as SQL migration files and applies that history to databases in different environments. During development, migrate dev creates and applies a migration. In production, use migrate deploy to apply reviewed, version-controlled migrations instead. Review generated SQL for data loss, renames, and the actual target before applying it.
This guide covers the general workflow for relational databases with Prisma ORM v7 (official docs checked 2026-11-23). Commands and configuration can vary by Prisma version. Examples are illustrative and were not run. MongoDB is outside this workflow because Prisma Migrate does not support it.
Why are development and production commands different?
prisma migrate dev is for development only. It replays the migration history in a temporary shadow database to detect schema drift, creates new SQL migrations from changes in the Prisma schema, and applies pending migrations to the development database. It records applied migrations in _prisma_migrations. It can ask to reset a development database when the migration history and schema conflict, so never use it against a production database. Prisma v7: Development and production Shadow database
prisma migrate deploy applies pending migration files in test and production environments. It generally belongs in a CI/CD pipeline. It does not use a shadow database, detect production schema drift, or generate artifacts such as Prisma Client. Plan those checks and generation steps separately. Prisma v7: Development and production
Example: add a field
Suppose Customer needs an optional preferred-language field:
model Customer {
id Int @id @default(autoincrement())
email String @unique
preferredLanguage String?
}First confirm that DATABASE_URL and Prisma configuration point to the development database. Then create and apply a named migration:
npx prisma migrate dev --name add_customer_preferred_languagePrisma writes SQL under a new folder in prisma/migrations/ and applies it to the development database. Open migration.sql and review what it does. Commit the schema file and the complete ordered migrations directory so teammates and deployment environments use the same history. In v7, migrate dev triggers artifact generation such as Prisma Client. Seeding runs only when you explicitly invoke npx prisma db seed. Prisma v7: Development and production Prisma ORM v7 seeding
Renaming a field can produce SQL that creates a new column and drops the old one, losing its data. If you need a data-preserving rename or a staged expand-and-contract change, create a draft without applying it:
npx prisma migrate dev --name rename_customer_field --create-onlyReview and edit the generated SQL, including any required data copy or database-specific statements, then apply it through the development workflow. Do not edit or delete migration files that have already been applied in shared environments; different environments would then have different histories. Customizing migrations
What does the shadow database do?
During migrate dev, Prisma replays the existing history in a temporary shadow database and compares its resulting schema with the development database. This detects drift from manual changes and helps evaluate whether a proposed migration could lose data. Production migrate deploy does not need or use a shadow database. About the shadow database
Some cloud databases do not allow tools to create and delete databases. In that case, configure a dedicated shadow database with SHADOW_DATABASE_URL and shadowDatabaseUrl. Never set the primary and shadow URLs to the same database: resetting the shadow database could delete real data. Limit its permissions to the dedicated temporary database.
Introducing Prisma Migrate to an existing database
An existing database already has tables and data. Applying an initial migration that recreates them would fail, so establish a baseline: a migration describing the current schema that Prisma records as already applied.
Compare the actual database structure with `schema.prisma`, and correct missing models, relations, or indexes.
Generate SQL that creates the Prisma schema from an empty database:
npx prisma migrate diff --from-empty --to-schema prisma/schema.prisma --script > prisma/migrations/0_init/migration.sqlReview the SQL and confirm it matches the real existing schema. This initial migration can create a new development database from scratch, but should not be applied to the existing production database.
Once the target database is verified to match the baseline, mark that migration as already applied:
npx prisma migrate resolve --applied 0_initmigrate resolve --applied updates _prisma_migrations; it does not execute the baseline SQL or change the database. Apply later migrations normally. If the project already has a migration folder, preserve and review its history and backups before reorganizing it. Prisma’s baseline instructions do not apply to MongoDB. Baselining a database
Before production deployment
Apply reviewed migration files in CI/CD with npx prisma migrate deploy. It can warn about modified applied migrations, but it does not detect drift between the production schema and migration history. If an emergency hotfix changed production directly, compare the database and history and plan a repair separately.
Review generated SQL, data backfills for required fields, and locking or deployment time for large changes. Check that application versions remain compatible with the old and new schemas during rollout, and prepare backups and recovery steps. migrate reset drops or resets a database/schema and is development-only; never run it in production. Prisma v7: Development and production
The practical distinction
Use migrate dev to create and review changes during development; use migrate deploy to apply reviewed migrations in production. For an existing database, verify an accurate baseline before recording it with migrate resolve --applied. Keeping these roles separate helps avoid data loss and divergent migration histories.