Skip to main content

prisma migrate

Manage database migrations with Prisma Migrate.

Subcommands

CommandDescription
prisma migrate devCreate migration from schema changes and apply to database
prisma migrate deployApply pending migrations in production
prisma migrate resetReset database and re-apply all migrations

prisma migrate dev

Create a migration from changes in Prisma schema, apply it to the database, and trigger generators (e.g., Prisma Client).

Usage

prisma migrate dev [options]
The datasource URL configuration is read from the Prisma config file (e.g., prisma.config.ts).

Options

--help
boolean
Display help message.Alias: -h
prisma migrate dev --help
--config
string
Custom path to your Prisma config file.
prisma migrate dev --config=./custom/prisma.config.ts
--schema
string
Custom path to your Prisma schema.
prisma migrate dev --schema=./prisma/schema.prisma
--url
string
Override the datasource URL from the Prisma config file.
prisma migrate dev --url="postgresql://user:password@localhost:5432/mydb"
--name
string
Name the migration (without prompting).Alias: -n
prisma migrate dev --name add_user_table
--create-only
boolean
Create a new migration but do not apply it. The migration will be empty if there are no changes in the Prisma schema.
prisma migrate dev --create-only

Examples

Basic usage

Create and apply migration:
prisma migrate dev
Interactive prompt:
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "mydb" at "localhost:5432"

✔ Enter a name for the new migration: › add_user_profile
Output:
The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20240301120000_add_user_profile/
    └─ migration.sql

✔ Your database is now in sync with your schema.

Create migration without applying

prisma migrate dev --create-only
Creates a migration file without applying it to the database. You can edit the SQL before applying with another prisma migrate dev run.

Name migration non-interactively

prisma migrate dev --name add_posts_table

Specify custom schema

prisma migrate dev --schema=./database/schema.prisma

Migration Warnings

If your migration might cause data loss, you’ll see warnings:
⚠️  Warnings for the current datasource:

  • You are about to drop the column `email` on the `User` table, which still contains 42 non-null values.

Are you sure you want to create and apply this migration? › (y/N)

Database Reset Needed

In some cases, migrate dev may determine that the database needs to be reset:
We need to reset the PostgreSQL database "mydb" at "localhost:5432"

You may use prisma migrate reset to drop the development database.
All data will be lost.

prisma migrate deploy

Apply pending migrations to update the database schema in production/staging.

Usage

prisma migrate deploy [options]
The datasource URL configuration is read from the Prisma config file (e.g., prisma.config.ts).

Options

--help
boolean
Display help message.Alias: -h
prisma migrate deploy --help
--config
string
Custom path to your Prisma config file.
prisma migrate deploy --config=./prisma.config.ts
--schema
string
Custom path to your Prisma schema.
prisma migrate deploy --schema=./schema.prisma

Examples

Deploy pending migrations

prisma migrate deploy
Output:
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "production_db" at "db.example.com:5432"

3 migrations found in prisma/migrations

The following migration(s) have been applied:

migrations/
  └─ 20240301120000_add_user_profile/
    └─ migration.sql
  └─ 20240301130000_add_posts/
    └─ migration.sql

✔ All migrations have been successfully applied.

No pending migrations

prisma migrate deploy
Output:
2 migrations found in prisma/migrations

✔ No pending migrations to apply.

Production Usage

Use migrate deploy in production environments as part of your deployment pipeline:
# In your CI/CD pipeline
npm install
npm run build
prisma migrate deploy
npm start

prisma migrate reset

Reset your database and apply all migrations. All data will be lost.

Usage

prisma migrate reset [options]
The datasource URL configuration is read from the Prisma config file (e.g., prisma.config.ts).

Options

--help
boolean
Display help message.Alias: -h
prisma migrate reset --help
--config
string
Custom path to your Prisma config file.
prisma migrate reset --config=./prisma.config.ts
--schema
string
Custom path to your Prisma schema.
prisma migrate reset --schema=./schema.prisma
--force
boolean
Skip the confirmation prompt.Alias: -f
prisma migrate reset --force

Examples

Reset with confirmation

prisma migrate reset
Interactive prompt:
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "dev_db" at "localhost:5432"

Are you sure you want to reset your database? All data will be lost. › (y/N)
Output after confirmation:
✔ Database reset successful

The following migration(s) have been applied:

migrations/
  └─ 20240301120000_init/
    └─ migration.sql
  └─ 20240301130000_add_users/
    └─ migration.sql

Reset without confirmation

prisma migrate reset --force
Skips the confirmation prompt. Useful in scripts and CI/CD pipelines for test databases.

When to Use Reset

  • During development when you want to start fresh
  • When testing migration scripts
  • When your migration history is broken
  • Before running integration tests in CI
⚠️ Warning: Never use migrate reset in production. It will delete all data.

Build docs developers (and LLMs) love