n8n-io/n8n · error · TypeORMError
No migration ${lastTimeExecutedMigration.name} was found in
Error message
No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options. What it means
During `migration:revert`, TypeORM loads the list of migrations already recorded in the DB, takes the most recent by timestamp, then looks that migration up by class name inside `connection.migrations` (the source array you configured). If the class is no longer present in source — e.g. it was deleted or removed from the array — it cannot be reverted and TypeORM throws a plain TypeORMError.
Source
Thrown at packages/@n8n/typeorm/src/migration/MigrationExecutor.ts:401
// if no migrations found in the database then nothing to revert
if (!lastTimeExecutedMigration) {
this.connection.logger.logSchemaBuild(
`No migrations were found in the database. Nothing to revert!`,
);
return;
}
// get all user's migrations in the source code
const allMigrations = this.getMigrations();
// find the instance of the migration we need to remove
const migrationToRevert = allMigrations.find(
(migration) => migration.name === lastTimeExecutedMigration!.name,
);
// if no migrations found in the database then nothing to revert
if (!migrationToRevert)
throw new TypeORMError(
`No migration ${lastTimeExecutedMigration.name} was found in the source code. Make sure you have this migration in your codebase and its included in the connection options.`,
);
// log information about migration execution
this.connection.logger.logSchemaBuild(
`${executedMigrations.length} migrations are already loaded in the database.`,
);
this.connection.logger.logSchemaBuild(
`${
lastTimeExecutedMigration.name
} is the last executed migration. It was executed on ${new Date(
lastTimeExecutedMigration.timestamp,
).toString()}.`,
);
this.connection.logger.logSchemaBuild(`Now reverting it...`);
// start transaction if its not started yet
let transactionStartedByUs = false;View on GitHub (pinned to 5ac6606e81)
Solutions
- Restore the missing migration class and re-add it to the DataSource `migrations` array, then re-run revert.
- If the migration is intentionally gone, manually delete its row from the migrations table (`DELETE FROM migrations WHERE timestamp = ...`) so the DB and source agree.
- Re-generate the migration with the same class name and a no-op up/down if you only need the bookkeeping cleared.
Example fix
// before — migration removed from source, but row still in DB // migrations: [Migration1700000000001, Migration1700000000003] // 002 deleted // after — restore it so revert can find it migrations: [Migration1700000000001, Migration1700000000002, Migration1700000000003]
Defensive patterns
Strategy: try-catch
Validate before calling
// Before reverting, confirm the last executed migration exists in source
const executed = await dataSource.query('SELECT * FROM migrations ORDER BY timestamp DESC');
const sourceNames = new Set(dataSource.migrations.map(m => m.name || m.constructor.name));
if (executed.length && !sourceNames.has(executed[0].name)) {
throw new Error(`Last executed migration ${executed[0].name} is missing from dataSource.migrations`);
} Try / catch
try { await migrationExecutor.undoLastMigration(); } catch (e) { if (e instanceof TypeORMError && /No migration.*was found in the source code/) { /* restore the class or DELETE the stale migrations-table row */ } throw e; } Prevention
- Never delete a migration class that production has already executed — supersede it instead.
- Keep your `migrations` array and the migrations folder in sync (load via glob, not hand-list).
- Before reverting, diff the migrations folder against the recorded migrations table.
When it happens
Trigger: Running `dataSource.undoLastMigration()` / CLI `migration:revert` after someone removed the last-run migration file or dropped it from the DataSource `migrations` array, while its row still exists in the migrations table.
Common situations: A squash/rebase deleted an old migration that the production DB still records as executed. Renaming a migration class so its name no longer matches the recorded row. Two developers where one reverted and the other branched before pulling.
Related errors
- ${migrationClassName} migration name is wrong. Migration cla
- Cannot save user <${this.email}>: Provided email is invalid
- Wrong driver: "${driverType}" given. Supported drivers are:
- Driver not Connected
- To use streams you should install pg-query-stream package. P
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/ec83b03a9d53b730.
Report an issue: GitHub.