{"record":{"id":"ec83b03a9d53b730","repo":"n8n-io/n8n","slug":"no-migration-lasttimeexecutedmigration-name-was","errorCode":null,"errorMessage":"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.","messagePattern":"No migration (.+?) was found in the source code\\. Make sure you have this migration in your codebase and its included in the connection options\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/migration/MigrationExecutor.ts","lineNumber":401,"sourceCode":"\t\t// if no migrations found in the database then nothing to revert\n\t\tif (!lastTimeExecutedMigration) {\n\t\t\tthis.connection.logger.logSchemaBuild(\n\t\t\t\t`No migrations were found in the database. Nothing to revert!`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// get all user's migrations in the source code\n\t\tconst allMigrations = this.getMigrations();\n\n\t\t// find the instance of the migration we need to remove\n\t\tconst migrationToRevert = allMigrations.find(\n\t\t\t(migration) => migration.name === lastTimeExecutedMigration!.name,\n\t\t);\n\n\t\t// if no migrations found in the database then nothing to revert\n\t\tif (!migrationToRevert)\n\t\t\tthrow new TypeORMError(\n\t\t\t\t`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.`,\n\t\t\t);\n\n\t\t// log information about migration execution\n\t\tthis.connection.logger.logSchemaBuild(\n\t\t\t`${executedMigrations.length} migrations are already loaded in the database.`,\n\t\t);\n\t\tthis.connection.logger.logSchemaBuild(\n\t\t\t`${\n\t\t\t\tlastTimeExecutedMigration.name\n\t\t\t} is the last executed migration. It was executed on ${new Date(\n\t\t\t\tlastTimeExecutedMigration.timestamp,\n\t\t\t).toString()}.`,\n\t\t);\n\t\tthis.connection.logger.logSchemaBuild(`Now reverting it...`);\n\n\t\t// start transaction if its not started yet\n\t\tlet transactionStartedByUs = false;","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/migration/MigrationExecutor.ts#L383-L419","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — migration removed from source, but row still in DB\n// migrations: [Migration1700000000001, Migration1700000000003]  // 002 deleted\n\n// after — restore it so revert can find it\nmigrations: [Migration1700000000001, Migration1700000000002, Migration1700000000003]","handlingStrategy":"try-catch","validationCode":"// Before reverting, confirm the last executed migration exists in source\nconst executed = await dataSource.query('SELECT * FROM migrations ORDER BY timestamp DESC');\nconst sourceNames = new Set(dataSource.migrations.map(m => m.name || m.constructor.name));\nif (executed.length && !sourceNames.has(executed[0].name)) {\n  throw new Error(`Last executed migration ${executed[0].name} is missing from dataSource.migrations`);\n}","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["typeorm","migrations","revert","schema-versioning"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}