drizzle-team/drizzle-orm · error · Error

Missing migration: ${journalEntry.tag}

Error message

Missing migration: ${journalEntry.tag}

What it means

An Error `Missing migration: ${journalEntry.tag}` thrown by readMigrationFiles() in drizzle-orm/src/op-sqlite/migrator.ts:19. For each journal entry it looks up migrations[`m${pad4(idx)}`]; if that key is absent (no SQL string shipped for that journal index) it throws, naming the migration tag (the human-friendly folder/name) that is missing.

Source

Thrown at drizzle-orm/src/op-sqlite/migrator.ts:19

import { useEffect, useReducer } from 'react';
import type { MigrationMeta } from '~/migrator.ts';
import type { OPSQLiteDatabase } from './driver.ts';

interface MigrationConfig {
	journal: {
		entries: { idx: number; when: number; tag: string; breakpoints: boolean }[];
	};
	migrations: Record<string, string>;
}

async function readMigrationFiles({ journal, migrations }: MigrationConfig): Promise<MigrationMeta[]> {
	const migrationQueries: MigrationMeta[] = [];

	for await (const journalEntry of journal.entries) {
		const query = migrations[`m${journalEntry.idx.toString().padStart(4, '0')}`];

		if (!query) {
			throw new Error(`Missing migration: ${journalEntry.tag}`);
		}

		try {
			const result = query.split('--> statement-breakpoint').map((it) => {
				return it;
			});

			migrationQueries.push({
				sql: result,
				bps: journalEntry.breakpoints,
				folderMillis: journalEntry.when,
				hash: '',
			});
		} catch {
			throw new Error(`Failed to parse migration: ${journalEntry.tag}`);
		}
	}

View on GitHub (pinned to b7862528fd)

Solutions

  1. Ensure every migration file output by drizzle-kit is imported and present in the migrations map passed to migrate().
  2. Verify the journal index matches: for entry idx N, key m + N zero-padded to 4 digits must exist.
  3. Re-run drizzle-kit generate and re-import all produced files; check the bundler is not dropping them.
  4. Co-locate journal + migrations imports so they cannot drift.

Example fix

// before — journal has 3 entries but only 2 files imported
import journal from './drizzle/meta/_journal.json';
import m0000 from './drizzle/0000_init.sql';
import m0001 from './drizzle/0001_users.sql';
await migrate(db, { journal, migrations: { m0000, m0001 } }); // throws: Missing migration: 0002_posts

// after — import every generated migration
import m0002 from './drizzle/0002_posts.sql';
await migrate(db, { journal, migrations: { m0000, m0001, m0002 } });
Defensive patterns

Strategy: validation

Validate before calling

function assertMigrationsComplete(
  journal: { entries: { idx: number; tag: string }[] },
  migrations: Record<string, string>,
): void {
  for (const e of journal.entries) {
    const key = `m${e.idx.toString().padStart(4, '0')}`;
    if (typeof migrations[key] !== 'string') {
      throw new Error(`Missing migration file for journal entry ${e.tag} (key ${key})`);
    }
  }
}

assertMigrationsComplete(journal, migrations);

Type guard

function isCompleteMigrationMap(
  journal: { entries: { idx: number }[] },
  migrations: Record<string, unknown>,
): boolean {
  return journal.entries.every((e) =>
    typeof migrations[`m${e.idx.toString().padStart(4, '0')}`] === 'string',
  );
}

Prevention

When it happens

Trigger: Calling migrate(db, { journal, migrations }) where the journal lists an entry whose corresponding m{idx} file is not present in the migrations map. Common when migration files were not bundled into the React Native app, or when the journal was regenerated but old file imports were dropped.

Common situations: Bundling the journal but forgetting to import the generated .sql files; partial migration import after `drizzle-kit generate`; Metro/React Native bundler tree-shaking the migration imports; mismatch between journal entries and shipped migration files after a rename.

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/ae21c173b97b7521.json. Report an issue: GitHub.