{"id":"ef026467da41d07c","repo":"typeorm/typeorm","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":"src/metadata/UniqueMetadata.ts","lineNumber":163,"sourceCode":"                        (column) => column.propertyPath === propertyName,\n                    )\n                    if (columnWithSameName) {\n                        return [columnWithSameName]\n                    }\n                    const relationWithSameName =\n                        this.entityMetadata.relations.find(\n                            (relation) =>\n                                relation.isWithJoinColumn &&\n                                relation.propertyName === propertyName,\n                        )\n                    if (relationWithSameName) {\n                        return relationWithSameName.joinColumns\n                    }\n                    const indexName = this.givenName\n                        ? '\"' + this.givenName + '\" '\n                        : \"\"\n                    const entityName = this.entityMetadata.targetName\n                    throw new TypeORMError(\n                        `Unique constraint ${indexName}contains column that is missing in the entity (${entityName}): ` +\n                            propertyName,\n                    )\n                })\n                .reduce((a, b) => a.concat(b))\n        }\n\n        this.columnNamesWithOrderingMap = Object.keys(map).reduce(\n            (updatedMap, key) => {\n                const column = this.entityMetadata.columns.find(\n                    (column) => column.propertyPath === key,\n                )\n                if (column) updatedMap[column.databasePath] = map[key]\n\n                return updatedMap\n            },\n            {} as { [key: string]: number },\n        )","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/metadata/UniqueMetadata.ts#L145-L181","documentation":"The unique-constraint analogue of the index column-missing error. Thrown during `UniqueMetadata.build()` when a column listed in `@Unique([\"...\"])` is neither a real column nor an owning relation with a join column on this entity. Same resolution logic as IndexMetadata: walk columns then `isWithJoinColumn` relations, abort if nothing matches.","triggerScenarios":"`@Unique(\"uq_x\", [\"misspelled\"])`; `@Unique([\"items\"])` where `items` is a @OneToMany (no join column on this entity); referencing a column that was removed; using a property name from an embeddable without the embed prefix.","commonSituations":"Renaming a column without updating @Unique; misunderstanding that unique constraints on relations must reference the owning side; copy-paste between entities; embeddable path mistakes.","solutions":["Verify each name in the @Unique array maps to a @Column or an owning relation (@ManyToOne / @OneToOne owner) on this entity.","For embeddable columns, use the full property path (e.g. `\"address.zip\"`) or place the @Unique inside the embeddable class.","Re-check after renames — search the codebase for the old column name in @Unique decorators."],"exampleFix":"// before\n@Entity()\n@Unique(\"uq_email\", [\"emial\"])  // typo\nexport class User { @Column() email: string }\n\n// after\n@Entity()\n@Unique(\"uq_email\", [\"email\"])\nexport class User { @Column() email: string }","handlingStrategy":"validation","validationCode":"// Mirror of the @Index validation, applied to @Unique column lists\nfunction validateUniqueColumns(\n  entityColumns: string[],\n  owningRelations: string[],\n  uniqueColumns: string[],\n): string[] {\n  const valid = new Set([...entityColumns, ...owningRelations])\n  return uniqueColumns.filter((c) => !valid.has(c))\n}","typeGuard":"function isColumnOrOwningRelation(meta: any, prop: string): boolean {\n  if (meta.columns.some((c: any) => c.propertyPath === prop)) return true\n  const r = meta.relations.find((rel: any) => rel.propertyName === prop)\n  return !!r && r.isWithJoinColumn\n}","tryCatchPattern":null,"preventionTips":["Keep @Unique column lists in sync with renames (grep the old name).","For embeddables, use the full property path or move the @Unique into the embeddable.","Initialize the DataSource in CI tests to catch schema-build errors."],"tags":["metadata","unique-constraint","schema-build","entity-definition"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}