prisma migrate
Manage database migrations with Prisma Migrate.Subcommands
| Command | Description |
|---|---|
prisma migrate dev | Create migration from schema changes and apply to database |
prisma migrate deploy | Apply pending migrations in production |
prisma migrate reset | Reset 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.config.ts).
Options
Display help message.Alias:
-hCustom path to your Prisma config file.
Custom path to your Prisma schema.
Override the datasource URL from the Prisma config file.
Name the migration (without prompting).Alias:
-nCreate a new migration but do not apply it. The migration will be empty if there are no changes in the Prisma schema.
Examples
Basic usage
Create and apply migration:Create migration without applying
prisma migrate dev run.
Name migration non-interactively
Specify custom schema
Migration Warnings
If your migration might cause data loss, you’ll see warnings:Database Reset Needed
In some cases,migrate dev may determine that the database needs to be reset:
prisma migrate deploy
Apply pending migrations to update the database schema in production/staging.Usage
prisma.config.ts).
Options
Display help message.Alias:
-hCustom path to your Prisma config file.
Custom path to your Prisma schema.
Examples
Deploy pending migrations
No pending migrations
Production Usage
Usemigrate deploy in production environments as part of your deployment pipeline:
prisma migrate reset
Reset your database and apply all migrations. All data will be lost.Usage
prisma.config.ts).
Options
Display help message.Alias:
-hCustom path to your Prisma config file.
Custom path to your Prisma schema.
Skip the confirmation prompt.Alias:
-fExamples
Reset with confirmation
Reset without confirmation
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
migrate reset in production. It will delete all data.
Related Commands
prisma db push- Push schema changes without migrationsprisma db pull- Introspect database to update schemaprisma generate- Generate Prisma Client