{"record":{"id":"0f6c697eec698904","repo":"n8n-io/n8n","slug":"index-indexname-contains-column-that-is-missing","errorCode":null,"errorMessage":"Index ${indexName}contains column that is missing in the entity (${entityName}): ${propertyPath}","messagePattern":"Index (.+?)contains column that is missing in the entity \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/metadata/IndexMetadata.ts","lineNumber":216,"sourceCode":"\t\t\t}\n\n\t\t\tthis.columns = columnPropertyPaths\n\t\t\t\t.map((propertyPath) => {\n\t\t\t\t\tconst columnWithSameName = this.entityMetadata.columns.find(\n\t\t\t\t\t\t(column) => column.propertyPath === propertyPath,\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 === propertyPath,\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`Index ${indexName}contains column that is missing in the entity (${entityName}): ` +\n\t\t\t\t\t\t\tpropertyPath,\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":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/metadata/IndexMetadata.ts#L198-L234","documentation":"Thrown by IndexMetadata.build when an @Index references a property path that is neither a column, a relation with a join column, nor otherwise resolvable on the entity. The builder first tries findColumnWithPropertyPath, then looks for a @ManyToOne/@OneToOne relation with isWithJoinColumn and matching propertyName; only if both fail does it throw, naming the index (if givenName was set) and the entity targetName.","triggerScenarios":"Declaring @Index('my_idx', ['foo']) where 'foo' is not a column on the same entity; renaming a column without updating index column lists; pointing an index at a property that lives only on a parent class without proper STI mapping.","commonSituations":"Typos in index column arrays, copy-pasted indices between entities, removing a column that an index still references, or referencing a getter-only / virtual property that has no backing column.","solutions":["Inspect every entry in the @Index columns array against the entity's @Column and join-column relations.","Rebuild the entity metadata (drop dist, restart) after renaming columns so stale decorators are not loaded.","If the column was intentionally removed, remove it from the index definition as well."],"exampleFix":"// before\n@Entity()\n@Index('idx_email', ['emial']) // typo\nexport class User { @Column() email: string; }\n\n// after\n@Entity()\n@Index('idx_email', ['email'])\nexport class User { @Column() email: string; }","handlingStrategy":"validation","validationCode":"// After DataSource.initialize(), verify every declared index resolves\nfunction validateIndices(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 idx of meta.indices) {\n      for (const givenPath of (idx.givenColumnNames as string[] | undefined) ?? []) {\n        if (!cols.has(givenPath) && !joinCols.has(givenPath)) {\n          problems.push(`${meta.targetName}.@Index('${idx.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('Index ') && err.message.includes('contains column that is missing')) {\n    // surface the offending index/entity pair to the operator\n  }\n  throw err;\n}","preventionTips":["Treat index column arrays as code: review them in PRs alongside the columns they reference.","Add a startup self-test (see validationCode) so a stale index fails the build, not production.","When renaming a column, search for it inside @Index decorators as well as queries."],"tags":["index","metadata","schema","startup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}