Fix Drizzle Generate Migration β Migration Not Created
DodaTech
Updated 2026-06-24
3 min read
In this tutorial, you'll learn about Fix Drizzle Generate Migration. We cover key concepts, practical examples, and best practices.
You run npx drizzle-kit generate after modifying your Drizzle schema. The command runs without errors but produces no new migration files in the drizzle/ directory. Or it creates a file that's empty (only the snapshot).
Wrong β
// src/db/schema.ts β modified
import { pgTable, serial, text } from 'drizzle-orm/pg-core';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name'),
// email column removed β expecting a migration to drop it
});
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
title: text('title'),
});
```bash
npx drizzle-kit generate
Output:
No schema changes detected.
But you clearly removed `email` from `users` and added `posts`!
## Right β
```bash
# Ensure drizzle-kit is the latest version
npm install drizzle-kit@latest
# Regenerate from scratch
rm -rf drizzle/
npx drizzle-kit generate
**If that doesn't work β check the snapshot:**
```bash
# Look at the meta journal
cat drizzle/meta/_journal.json
# Check if the previous snapshot matches current schema
**Add verbose logging:**
```bash
npx drizzle-kit generate --verbose
# Shows what changes were detected (or not)
**Ensure the config points to the correct schema file:**
```<a href="/programming-languages/typescript/">typescript</a>
// drizzle.config.ts
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/db/schema.ts', // β check this path
out: './drizzle',
dialect: '<a href="/databases/postgresql/">postgresql</a>',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
verbose: true,
strict: true,
});
**If the migration file is created but empty:**
The initial migration might already have captured all tables. Check the directory:
```bash
ls -la drizzle/
# Should show: 0000_*.sql, meta/, ...
# Check if the meta tracks the current schema state
cat drizzle/meta/0000_snapshot.json | head -20
**Workaround β generate manually:**
```bash
# If automatic generation fails, write the SQL manually:
npx drizzle-kit push:pg --dry-run
# Copy the SQL and save as a migration file
## Root Cause
Drizzle Kit compares the **current schema definition** against the **last snapshot** in `drizzle/meta/`. If the snapshot is lost, corrupted, or the schema file path is wrong, Drizzle can't detect changes. Also, if the schema exports haven't changed (e.g., fields are modified but the exports remain), the generator may think nothing changed.
## Prevention
- Always commit the `drizzle/` directory to version control.
- Run `drizzle-kit generate` immediately after schema changes β don't batch many changes.
- Use `--verbose` to see what the generator detects.
- If the meta gets out of sync, delete `drizzle/` and regenerate.
## Common Mistakes with generate migration
1. **Misunderstanding that `String` is `[Char]` with poor performance for large text operations**
2. **Using `foldl` instead of `foldl'` causing stack overflow on large lists**
3. **Forgetting `deriving (Show, Eq)` on custom data types needed for debugging**
These mistakes appear frequently in real-world DRIZZLE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
## Practice Exercise
**Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.**
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
## FAQ
<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I manually edit migration files?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes β Drizzle generates SQL files in <code>drizzle/</code>. You can edit them before they're applied.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: What's the `_journal.json` file for?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: It tracks which migration files have been applied and the current snapshot state.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: How do I roll back a Drizzle migration?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Drizzle doesn't have builtβin rollback. Create a new migration that reverses the previous changes.</p>
</div></details><details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">**Q: Can I generate migrations without a database connection?**</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>A: Yes β <code>drizzle-kit generate</code> only needs the schema file, not a running database.</p>
</div></details>
---
*Migration generation is covered in the [DodaTech Drizzle ORM course](https://dodatech.com/courses/drizzle).*
β Previous
How to Export High Resolution from Draw.io
Next β
Fix Drizzle Kit Push Error β Schema Push Fails
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro