Installation
Configuration
Create adrizzle.config.ts file in your project root:
drizzle.config.ts
You can also use a
drizzle.config.js file or specify configuration via CLI options.Core Commands
Generate Migrations
Generate SQL migration files from your schema changes:- Drizzle Kit reads your schema file
- Compares it with the previous snapshot (if exists)
- Generates SQL migration files for the differences
- Prompts you for input on ambiguous cases (renames, etc.)
--config- Path to config file--schema- Path to schema file(s)--out- Output directory for migrations (default:drizzle)--name- Custom migration name--custom- Create empty migration file for custom SQL--dialect- Database dialect--breakpoints- Add SQL breakpoints
Push Schema
Push schema changes directly to the database without generating migration files:--strict- Always ask for confirmation--force- Auto-approve all data loss statements--verbose- Print all SQL statements
- Local development and prototyping
- Testing schema changes quickly
- Syncing schema to preview environments
Apply Migrations
Apply pending migrations to your database:- Connects to your database
- Creates migrations table if it doesn’t exist
- Runs all pending migrations in order
- Updates the migrations table
Introspect Database
Generate Drizzle schema from an existing database (also known aspull):
--introspect-casing- Choose casing:camelorpreserve--tablesFilter- Filter specific tables--schemaFilters- Filter specific schemas
- Migrating to Drizzle from another ORM
- Working with existing databases
- Keeping schema in sync with database changes
Check Migrations
Validate migration files for consistency:Drop Migration
Remove the last generated migration:Database Dialects
Drizzle Kit supports multiple database dialects:- PostgreSQL
- MySQL
- SQLite
- Turso
drizzle.config.ts
aws-data-api- AWS RDS Data APIpglite- PGlite
Migration Workflow
1
Define your schema
Create or modify your schema file:
src/db/schema.ts
2
Generate migration
Run the generate command:This creates a migration file in your output directory:
drizzle/0000_users_table.sql
3
Review migration
Inspect the generated SQL to ensure it matches your intentions. You can edit the migration file if needed.
4
Apply migration
Run the migrate command to apply changes:Or apply migrations programmatically in your application:
Common Patterns
Environment-based Configuration
drizzle.config.ts
Multiple Schema Files
drizzle.config.ts
Custom Migration Prefixes
drizzle.config.ts
Table Filters for Introspection
drizzle.config.ts
Package Scripts
Add these scripts to yourpackage.json for convenience:
package.json
Best Practices
1
Version control migrations
Always commit migration files to version control. They represent your database history.
2
Never edit applied migrations
Once a migration has been applied to production, create a new migration for changes instead of editing the existing one.
3
Test migrations
Test migrations in development and staging before applying to production.
4
Use push for development
Use
drizzle-kit push for rapid development, but switch to migrations before deploying.5
Review generated SQL
Always review the generated SQL before applying migrations to production.
Troubleshooting
Migration conflicts
If you encounter migration conflicts when working in a team:Connection issues
Verify your database credentials:Schema validation
If you get schema validation errors, ensure yourdrizzle-orm version is compatible:
Next Steps
Drizzle Studio
Explore your database with the visual database browser
Migrations Guide
Learn advanced migration patterns and strategies