{"record":{"id":"ccf31cb3e15c6d71","repo":"n8n-io/n8n","slug":"supplied-unique-constraint-was-not-found-in-table","errorCode":null,"errorMessage":"Supplied unique constraint was not found in table ${table.name}","messagePattern":"Supplied unique constraint was not found in table (.+?)","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts","lineNumber":791,"sourceCode":"\t\t);\n\t\tawait this.recreateTable(changedTable, table);\n\t}\n\n\t/**\n\t * Drops an unique constraint.\n\t */\n\tasync dropUniqueConstraint(\n\t\ttableOrName: Table | string,\n\t\tuniqueOrName: TableUnique | string,\n\t): Promise<void> {\n\t\tconst table = InstanceChecker.isTable(tableOrName)\n\t\t\t? tableOrName\n\t\t\t: await this.getCachedTable(tableOrName);\n\t\tconst uniqueConstraint = InstanceChecker.isTableUnique(uniqueOrName)\n\t\t\t? uniqueOrName\n\t\t\t: table.uniques.find((u) => u.name === uniqueOrName);\n\t\tif (!uniqueConstraint)\n\t\t\tthrow new TypeORMError(`Supplied unique constraint was not found in table ${table.name}`);\n\n\t\tawait this.dropUniqueConstraints(table, [uniqueConstraint]);\n\t}\n\n\t/**\n\t * Creates an unique constraints.\n\t */\n\tasync dropUniqueConstraints(\n\t\ttableOrName: Table | string,\n\t\tuniqueConstraints: TableUnique[],\n\t): Promise<void> {\n\t\tconst table = InstanceChecker.isTable(tableOrName)\n\t\t\t? tableOrName\n\t\t\t: await this.getCachedTable(tableOrName);\n\n\t\t// clone original table and remove unique constraints from cloned table\n\t\tconst changedTable = table.clone();\n\t\tuniqueConstraints.forEach((uniqueConstraint) =>","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts#L773-L809","documentation":"dropUniqueConstraint() resolves the unique constraint by name (or object) against the cached table; if none matches it throws TypeORMError. The unique constraint you are trying to drop does not exist in the table definition TypeORM has loaded.","triggerScenarios":"Calling dropUniqueConstraint(table, 'constraintName') where 'constraintName' is not present in table.uniques of the cached table.","commonSituations":"Re-running a migration that already dropped it, a typo in the constraint name (SQLite often auto-generates these names), or stale cached metadata.","solutions":["Resolve the actual constraint name from the live schema — SQLite may auto-name it, so list uniques first via getTable().","Make the drop idempotent — check existence first.","Re-fetch the table via getTable() if metadata may be stale."],"exampleFix":"// before\nawait queryRunner.dropUniqueConstraint('user', 'UQ_user_email');\n\n// after\nconst table = await queryRunner.getTable('user');\nif (table?.uniques.some((u) => u.name === 'UQ_user_email')) {\n  await queryRunner.dropUniqueConstraint(table!, 'UQ_user_email');\n}","handlingStrategy":"validation","validationCode":"const table = await queryRunner.getTable('user');\nif (table?.uniques.some((u) => u.name === 'UQ_user_email')) {\n  await queryRunner.dropUniqueConstraint(table!, 'UQ_user_email');\n}","typeGuard":"const uniqueExists = async (qr: QueryRunner, tableName: string, name: string): Promise<boolean> =>\n  Boolean((await qr.getTable(tableName))?.uniques.some((u) => u.name === name));","tryCatchPattern":null,"preventionTips":["Resolve the real constraint name from the live schema — SQLite often auto-names these.","Make constraint drops idempotent.","Re-fetch table metadata when stale."],"tags":["database","migration","sqlite","constraints"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}