Skip to main content
Prisma Migrate is an imperative database schema migration tool that enables you to make changes to your database schema. Migrations are auto-generated based on the Prisma schema changes but are fully customizable.

What is Prisma Migrate?

Prisma Migrate generates SQL migration files based on changes you make to your Prisma schema. These migrations can be applied to your database to keep it in sync with your schema. Key features include:
  • Auto-generated migrations: Changes to your Prisma schema automatically generate SQL migration files
  • Customizable: Generated migration files can be edited before applying
  • Version control friendly: Migration files are stored in your project and can be committed to git
  • Database agnostic: Works with PostgreSQL, MySQL, SQLite, SQL Server, and CockroachDB

Core Concepts

Migration Files

Migration files are stored in the prisma/migrations directory. Each migration is in its own folder with a timestamp and name:
prisma/
  └─ migrations/
    ├─ 20201014154943_init/
    │  └─ migration.sql
    ├─ 20201106130852_add_users/
    │  └─ migration.sql
    └─ migration_lock.toml

Migration File Format

Each migration folder contains a migration.sql file with the SQL statements:
-- CreateTable
CREATE TABLE "User" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "email" TEXT NOT NULL,
    "name" TEXT
);

-- CreateIndex
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");

Migration Lock File

The migration_lock.toml file locks the database provider:
# Please do not edit this file manually
provider = "sqlite"

Development vs Production

Prisma Migrate has different workflows for development and production environments:

Development Commands

  • prisma migrate dev - Create and apply migrations during development
  • prisma migrate reset - Reset your database and apply all migrations

Production Commands

  • prisma migrate deploy - Apply pending migrations in production
  • prisma migrate status - Check migration status
  • prisma migrate resolve - Resolve migration issues

Configuration

The datasource URL configuration is read from your Prisma config file (e.g., prisma.config.ts):
import { defineConfig } from '@prisma/config'

export default defineConfig({
  datasource: {
    url: process.env.DATABASE_URL
  },
  schema: 'prisma/schema.prisma'
})

When to Use Prisma Migrate

Prisma Migrate is ideal when you:
  • Need version-controlled database migrations
  • Want to track schema changes over time
  • Are working in a team environment
  • Need to deploy schema changes to production
For rapid prototyping, consider using db push instead.

Next Steps

Getting Started

Create your first migration

Migration Workflows

Learn development and production workflows

Schema Prototyping

Use db push for rapid iteration

Existing Databases

Add Prisma Migrate to existing databases

Build docs developers (and LLMs) love