{"record":{"id":"4ad9fb0478da1ff9","repo":"n8n-io/n8n","slug":"column-columnname-was-not-found-in-table-m","errorCode":null,"errorMessage":"Column \"${columnName}\" was not found in table \"${metadata.name}\"","messagePattern":"Column \"(.+?)\" was not found in table \"(.+?)\"","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/entity-manager/EntityManager.ts","lineNumber":948,"sourceCode":"\t */\n\tmaximum<Entity extends ObjectLiteral>(\n\t\tentityClass: EntityTarget<Entity>,\n\t\tcolumnName: PickKeysByType<Entity, number>,\n\t\twhere?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],\n\t): Promise<number | null> {\n\t\treturn this.callAggregateFun(entityClass, 'MAX', columnName, where);\n\t}\n\n\tprivate async callAggregateFun<Entity extends ObjectLiteral>(\n\t\tentityClass: EntityTarget<Entity>,\n\t\tfnName: 'SUM' | 'AVG' | 'MIN' | 'MAX',\n\t\tcolumnName: PickKeysByType<Entity, number>,\n\t\twhere: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[] = {},\n\t): Promise<number | null> {\n\t\tconst metadata = this.connection.getMetadata(entityClass);\n\t\tconst column = metadata.columns.find((item) => item.propertyPath === columnName);\n\t\tif (!column) {\n\t\t\tthrow new TypeORMError(`Column \"${columnName}\" was not found in table \"${metadata.name}\"`);\n\t\t}\n\n\t\tconst result = await this.createQueryBuilder(entityClass, metadata.name)\n\t\t\t.setFindOptions({ where })\n\t\t\t.select(`${fnName}(${this.connection.driver.escape(column.databaseName)})`, fnName)\n\t\t\t.getRawOne();\n\t\treturn result[fnName] === null ? null : parseFloat(result[fnName]);\n\t}\n\n\t/**\n\t * Finds entities that match given find options.\n\t */\n\tasync find<Entity extends ObjectLiteral>(\n\t\tentityClass: EntityTarget<Entity>,\n\t\toptions?: FindManyOptions<Entity>,\n\t): Promise<Entity[]> {\n\t\tconst metadata = this.connection.getMetadata(entityClass);\n\t\treturn this.createQueryBuilder<Entity>(","sourceCodeStart":930,"sourceCodeEnd":966,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/entity-manager/EntityManager.ts#L930-L966","documentation":"Inside EntityManager.callAggregateFun (used by sum/average/min/max), TypeORM resolves the requested column against entity metadata by propertyPath. If metadata.columns has no entry whose propertyPath matches the supplied columnName, it throws a TypeORMError naming the column and the table metadata. The lookup is purely on entity metadata — the underlying database schema is never consulted, so the error fires even when the DB column exists but isn't mapped.","triggerScenarios":"Calling `manager.sum(Entity, 'totalPrice', ...)` where `totalPrice` is not a @Column-decorated property; passing a database column name instead of the TS property name; passing a nested path like `'profile.score'` when the relation/embeddable isn't mapped; querying a column added in a migration but not yet in the entity class; passing a getter or computed (non-persisted) property.","commonSituations":"Stale entity after a schema migration; mixing DB column names with property names; rename refactor that updated the DB but not the entity; querying an embedded column without the full dotted path.","solutions":["Use the @Column property name on the entity, not the snake_case database column name.","Regenerate/sync the entity after schema changes (run the migration, then update the @Column decorator or rebuild metadata).","For nested/embedded values, pass the full property path, e.g. `'profile.score'`, and confirm the embeddable/relation is mapped.","Confirm the property is decorated with @Column (relations/getters are not aggregatable)."],"exampleFix":"// before - using DB column name\nawait manager.sum(Order, 'total_price');\n\n// after - using the @Column property name\n@Entity()\nclass Order {\n  @Column() totalPrice!: number;\n}\nawait manager.sum(Order, 'totalPrice');","handlingStrategy":"type-guard","validationCode":"// Confirm the column exists in metadata before calling sum/avg/min/max\nconst meta = connection.getMetadata(Entity);\nconst valid = meta.columns.some(c => c.propertyPath === columnName);\nif (!valid) throw new Error(`Refusing to aggregate: ${columnName} is not a mapped column`);\nawait manager.sum(Entity, columnName as any, where);","typeGuard":"function isMappedColumn<Entity>(meta: import('@n8n/typeorm').EntityMetadata<Entity>, name: string): boolean {\n  return meta.columns.some(c => c.propertyPath === name);\n}","tryCatchPattern":null,"preventionTips":["Always pass @Column property names, not DB column names.","Regenerate entities after schema migrations.","Type aggregate arguments via keyof Entity rather than string.","For embedded paths, use the full dotted property path."],"tags":["typeorm","aggregates","metadata","api-misuse"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}