{"record":{"id":"dbe500ae292dff06","repo":"n8n-io/n8n","slug":"referenced-column-joincolumn-referencedcolumnnam","errorCode":null,"errorMessage":"Referenced column ${joinColumn.referencedColumnName} was not found in entity ${relation.entityMetadata.name}","messagePattern":"Referenced column (.+?) was not found in entity (.+?)","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/metadata-builder/JunctionEntityMetadataBuilder.ts","lineNumber":233,"sourceCode":"\t/**\n\t * Collects referenced columns from the given join column args.\n\t */\n\tprotected collectReferencedColumns(\n\t\trelation: RelationMetadata,\n\t\tjoinTable: JoinTableMetadataArgs,\n\t): ColumnMetadata[] {\n\t\tconst hasAnyReferencedColumnName = joinTable.joinColumns\n\t\t\t? joinTable.joinColumns.find((joinColumn) => !!joinColumn.referencedColumnName)\n\t\t\t: false;\n\t\tif (!joinTable.joinColumns || (joinTable.joinColumns && !hasAnyReferencedColumnName)) {\n\t\t\treturn relation.entityMetadata.columns.filter((column) => column.isPrimary);\n\t\t} else {\n\t\t\treturn joinTable.joinColumns.map((joinColumn) => {\n\t\t\t\tconst referencedColumn = relation.entityMetadata.columns.find(\n\t\t\t\t\t(column) => column.propertyName === joinColumn.referencedColumnName,\n\t\t\t\t);\n\t\t\t\tif (!referencedColumn)\n\t\t\t\t\tthrow new TypeORMError(\n\t\t\t\t\t\t`Referenced column ${joinColumn.referencedColumnName} was not found in entity ${relation.entityMetadata.name}`,\n\t\t\t\t\t);\n\n\t\t\t\treturn referencedColumn;\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Collects inverse referenced columns from the given join column args.\n\t */\n\tprotected collectInverseReferencedColumns(\n\t\trelation: RelationMetadata,\n\t\tjoinTable: JoinTableMetadataArgs,\n\t): ColumnMetadata[] {\n\t\tconst hasInverseJoinColumns = !!joinTable.inverseJoinColumns;\n\t\tconst hasAnyInverseReferencedColumnName = hasInverseJoinColumns\n\t\t\t? joinTable.inverseJoinColumns!.find((joinColumn) => !!joinColumn.referencedColumnName)","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata-builder/JunctionEntityMetadataBuilder.ts#L215-L251","documentation":"When building the junction (join) entity for a @ManyToMany relation, TypeORM resolves each `referencedColumnName` you declared in `@JoinTable({ joinColumns: [...] })` against `relation.entityMetadata.columns`. If the named column does not exist as a property on the owning entity, the resolution returns undefined and TypeORM throws, because it cannot wire the join table without knowing which column it points at.","triggerScenarios":"Writing `@JoinTable({ joinColumn: { name: 'user_id', referencedColumnName: 'uuid' } })` when the owning entity has no `uuid` property (typo, or the column is on the inverse entity, or it was renamed). Referencing a column that lives in an embeddable that is not flattened into `columns`.","commonSituations":"Renaming an entity property but forgetting to update the @JoinTable referencedColumnName. Mixing up the owning vs inverse side and pointing referencedColumnName at a column on the wrong entity.","solutions":["Verify the `referencedColumnName` string exactly matches a `@Column`/`@PrimaryColumn` property name on the OWNING entity of the @ManyToMany.","If you want the junction to reference the inverse entity's column, move the `@JoinTable` to the other side and use `inverseJoinColumns`.","Drop the explicit `referencedColumnName` and let TypeORM default to the primary key."],"exampleFix":"// before — 'uuid' does not exist on the owning entity\n@ManyToMany(() => Tag)\n@JoinTable({ joinColumn: { name: 'post_id', referencedColumnName: 'uuid' } })\ntags: Tag[];\n\n// after — reference the actual PK property\n@ManyToMany(() => Tag)\n@JoinTable({ joinColumn: { name: 'post_id', referencedColumnName: 'id' } })\ntags: Tag[];","handlingStrategy":"validation","validationCode":"// Validate every @JoinTable referencedColumnName resolves on the owning entity\nfor (const m of dataSource.entityMetadatas) {\n  for (const r of m.manyToManyRelations) {\n    if (!r.joinTable?.joinColumns) continue;\n    for (const jc of r.joinTable.joinColumns) {\n      if (jc.referencedColumnName && !m.columns.some(c => c.propertyName === jc.referencedColumnName)) {\n        throw new Error(`${m.name}: joinColumn references unknown column ${jc.referencedColumnName}`);\n      }\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try { await dataSource.initialize(); } catch (e) { if (e instanceof TypeORMError && /Referenced column.*was not found/) { /* check @JoinTable joinColumns */ } throw e; }","preventionTips":["Use entity property names (not DB column names) in `referencedColumnName`.","Omit `referencedColumnName` to default to the primary key when possible.","Re-check @JoinTable after renaming any property on the owning entity."],"tags":["typeorm","relations","many-to-many","join-table","schema-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}