n8n-io/n8n · error · TypeORMError

Column "${columnName}" was not found in table "${metadata.na

Error message

Column "${columnName}" was not found in table "${metadata.name}"

What it means

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.

Source

Thrown at packages/@n8n/typeorm/src/entity-manager/EntityManager.ts:948

	 */
	maximum<Entity extends ObjectLiteral>(
		entityClass: EntityTarget<Entity>,
		columnName: PickKeysByType<Entity, number>,
		where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
	): Promise<number | null> {
		return this.callAggregateFun(entityClass, 'MAX', columnName, where);
	}

	private async callAggregateFun<Entity extends ObjectLiteral>(
		entityClass: EntityTarget<Entity>,
		fnName: 'SUM' | 'AVG' | 'MIN' | 'MAX',
		columnName: PickKeysByType<Entity, number>,
		where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[] = {},
	): Promise<number | null> {
		const metadata = this.connection.getMetadata(entityClass);
		const column = metadata.columns.find((item) => item.propertyPath === columnName);
		if (!column) {
			throw new TypeORMError(`Column "${columnName}" was not found in table "${metadata.name}"`);
		}

		const result = await this.createQueryBuilder(entityClass, metadata.name)
			.setFindOptions({ where })
			.select(`${fnName}(${this.connection.driver.escape(column.databaseName)})`, fnName)
			.getRawOne();
		return result[fnName] === null ? null : parseFloat(result[fnName]);
	}

	/**
	 * Finds entities that match given find options.
	 */
	async find<Entity extends ObjectLiteral>(
		entityClass: EntityTarget<Entity>,
		options?: FindManyOptions<Entity>,
	): Promise<Entity[]> {
		const metadata = this.connection.getMetadata(entityClass);
		return this.createQueryBuilder<Entity>(

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Use the @Column property name on the entity, not the snake_case database column name.
  2. Regenerate/sync the entity after schema changes (run the migration, then update the @Column decorator or rebuild metadata).
  3. For nested/embedded values, pass the full property path, e.g. `'profile.score'`, and confirm the embeddable/relation is mapped.
  4. Confirm the property is decorated with @Column (relations/getters are not aggregatable).

Example fix

// before - using DB column name
await manager.sum(Order, 'total_price');

// after - using the @Column property name
@Entity()
class Order {
  @Column() totalPrice!: number;
}
await manager.sum(Order, 'totalPrice');
Defensive patterns

Strategy: type-guard

Validate before calling

// Confirm the column exists in metadata before calling sum/avg/min/max
const meta = connection.getMetadata(Entity);
const valid = meta.columns.some(c => c.propertyPath === columnName);
if (!valid) throw new Error(`Refusing to aggregate: ${columnName} is not a mapped column`);
await manager.sum(Entity, columnName as any, where);

Type guard

function isMappedColumn<Entity>(meta: import('@n8n/typeorm').EntityMetadata<Entity>, name: string): boolean {
  return meta.columns.some(c => c.propertyPath === name);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/4ad9fb0478da1ff9. Report an issue: GitHub.