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 theprisma/migrations directory. Each migration is in its own folder with a timestamp and name:
Migration File Format
Each migration folder contains amigration.sql file with the SQL statements:
Migration Lock File
Themigration_lock.toml file locks the database provider:
Development vs Production
Prisma Migrate has different workflows for development and production environments:Development Commands
prisma migrate dev- Create and apply migrations during developmentprisma migrate reset- Reset your database and apply all migrations
Production Commands
prisma migrate deploy- Apply pending migrations in productionprisma migrate status- Check migration statusprisma migrate resolve- Resolve migration issues
Configuration
The datasource URL configuration is read from your Prisma config file (e.g.,prisma.config.ts):
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
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