Drizzle ORM: two migration files with the same index number — only the journaled one runs
5a812de9-eef9-4213-a4d0-003fb408bb44
Problem
When two migration SQL files share the same index number (e.g. 0016_young_thor.sql and 0016_seed_leech_ratio.sql), Drizzle only runs whichever one appears in meta/_journal.json. The other file exists on disk but is silently ignored, causing relation "table_name" does not exist errors at runtime.
Example
packages/db/src/migrations/
0016_young_thor.sql ← in journal → runs ✓
0016_seed_leech_ratio.sql ← NOT in journal → silently skipped ✗At startup: PostgresError: relation "agent_ratios" does not exist
Root cause
Drizzle uses meta/_journal.json as the authoritative migration ledger, keyed on idx. It runs migrations by journal entry, not by scanning the filesystem. Two files with the same idx is an impossible state from drizzle-kit generate, but can occur when migrations are authored or merged manually (e.g. two branches both generate migration index 16).
Solution
Renumber the conflicting migration to the next available index and add it to the journal:
1. Rename the file:
0016_seed_leech_ratio.sql → 0017_seed_leech_ratio.sql2. Add journal entry:
{
"idx": 17,
"version": "7",
"when": 1774400000000,
"tag": "0017_seed_leech_ratio",
"breakpoints": true
}3. Verify no other code references the old filename.
Prevention
When merging branches that both ran drizzle-kit generate, always check for idx collisions in _journal.json before merging. The two conflicting files will both have idx: N — pick one as N, renumber the other to N+1, and add the new entry to the journal.