{"record":{"id":"429b5965506cc8e6","repo":"n8n-io/n8n","slug":"unique-constraint-indexname-contains-column-that","errorCode":null,"errorMessage":"Unique constraint ${indexName}contains column that is missing in the entity (${entityName}): ${propertyName}","messagePattern":"Unique constraint (.+?)contains column that is missing in the entity \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/metadata/UniqueMetadata.ts","lineNumber":138,"sourceCode":"\t\t\t}\n\n\t\t\tthis.columns = columnPropertyPaths\n\t\t\t\t.map((propertyName) => {\n\t\t\t\t\tconst columnWithSameName = this.entityMetadata.columns.find(\n\t\t\t\t\t\t(column) => column.propertyPath === propertyName,\n\t\t\t\t\t);\n\t\t\t\t\tif (columnWithSameName) {\n\t\t\t\t\t\treturn [columnWithSameName];\n\t\t\t\t\t}\n\t\t\t\t\tconst relationWithSameName = this.entityMetadata.relations.find(\n\t\t\t\t\t\t(relation) => relation.isWithJoinColumn && relation.propertyName === propertyName,\n\t\t\t\t\t);\n\t\t\t\t\tif (relationWithSameName) {\n\t\t\t\t\t\treturn relationWithSameName.joinColumns;\n\t\t\t\t\t}\n\t\t\t\t\tconst indexName = this.givenName ? '\"' + this.givenName + '\" ' : '';\n\t\t\t\t\tconst entityName = this.entityMetadata.targetName;\n\t\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t\t`Unique constraint ${indexName}contains column that is missing in the entity (${entityName}): ` +\n\t\t\t\t\t\t\tpropertyName,\n\t\t\t\t\t);\n\t\t\t\t})\n\t\t\t\t.reduce((a, b) => a.concat(b));\n\t\t}\n\n\t\tthis.columnNamesWithOrderingMap = Object.keys(map).reduce(\n\t\t\t(updatedMap, key) => {\n\t\t\t\tconst column = this.entityMetadata.columns.find((column) => column.propertyPath === key);\n\t\t\t\tif (column) updatedMap[column.databasePath] = map[key];\n\n\t\t\t\treturn updatedMap;\n\t\t\t},\n\t\t\t{} as { [key: string]: number },\n\t\t);\n\n\t\tthis.name = this.givenName","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata/UniqueMetadata.ts#L120-L156","documentation":"Thrown by UniqueMetadata.build when an @Unique constraint lists a property that is neither a column nor a join-column relation on the entity. The resolution mirrors IndexMetadata: find a column by propertyPath, then a join-column relation by propertyName; on failure it throws, naming the unique constraint (givenName) and the entity targetName.","triggerScenarios":"Declaring @Unique('uq', ['missingField']) or @Unique(['missingField']) where the property is not a @Column or join-column relation.","commonSituations":"Typos in unique-constraint column arrays, dropping a column but leaving it in @Unique, pointing a unique constraint at a computed/getter property with no DB column.","solutions":["Cross-check each entry in the @Unique columns array against the entity's @Column and join-column relations.","After renaming a column, update every @Unique referencing it.","Remove the @Unique entry for any deleted column."],"exampleFix":"// before\n@Entity()\n@Unique('uq_user_email', ['emial'])\nexport class User { @Column() email: string; }\n\n// after\n@Entity()\n@Unique('uq_user_email', ['email'])\nexport class User { @Column() email: string; }","handlingStrategy":"validation","validationCode":"function validateUniques(dataSource: DataSource): string[] {\n  const problems: string[] = [];\n  for (const meta of dataSource.entityMetadatas) {\n    const cols = new Set(meta.columns.map((c) => c.propertyPath));\n    const joinCols = new Set(\n      meta.relations.filter((r) => r.isWithJoinColumn).map((r) => r.propertyName),\n    );\n    for (const uq of meta.uniques) {\n      for (const givenPath of (uq.givenColumnNames as string[] | undefined) ?? []) {\n        if (!cols.has(givenPath) && !joinCols.has(givenPath)) {\n          problems.push(`${meta.targetName}.@Unique('${uq.givenName}') -> missing ${givenPath}`);\n        }\n      }\n    }\n  }\n  return problems;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dataSource.initialize();\n} catch (err) {\n  if (err.message.includes('Unique constraint') && err.message.includes('missing in the entity')) {\n    // surface the unique-constraint/entity pair\n  }\n  throw err;\n}","preventionTips":["Run the post-init Unique validator above in CI.","Keep unique-constraint column lists versioned alongside the columns they cover.","On column deletion, search @Unique decorators for references."],"tags":["unique-constraint","metadata","schema","startup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}