{"record":{"id":"23a66bd0f3055a1c","repo":"n8n-io/n8n","slug":"entity-where-values-should-be-inserted-is-not-spec","errorCode":null,"errorMessage":"Entity where values should be inserted is not specified. Call \"qb.into(entity)\" method to specify it.","messagePattern":"Entity where values should be inserted is not specified\\. Call \"qb\\.into\\(entity\\)\" method to specify it\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/QueryBuilder.ts","lineNumber":594,"sourceCode":"\t * schema name, otherwise returns escaped table name.\n\t */\n\tprotected getTableName(tablePath: string): string {\n\t\treturn tablePath\n\t\t\t.split('.')\n\t\t\t.map((i) => {\n\t\t\t\t// this condition need because in SQL Server driver when custom database name was specified and schema name was not, we got `dbName..tableName` string, and doesn't need to escape middle empty string\n\t\t\t\tif (i === '') return i;\n\t\t\t\treturn this.escape(i);\n\t\t\t})\n\t\t\t.join('.');\n\t}\n\n\t/**\n\t * Gets name of the table where insert should be performed.\n\t */\n\tprotected getMainTableName(): string {\n\t\tif (!this.expressionMap.mainAlias)\n\t\t\tthrow new TypeORMError(\n\t\t\t\t`Entity where values should be inserted is not specified. Call \"qb.into(entity)\" method to specify it.`,\n\t\t\t);\n\n\t\tif (this.expressionMap.mainAlias.hasMetadata)\n\t\t\treturn this.expressionMap.mainAlias.metadata.tablePath;\n\n\t\treturn this.expressionMap.mainAlias.tablePath!;\n\t}\n\n\t/**\n\t * Specifies FROM which entity's table select/update/delete will be executed.\n\t * Also sets a main string alias of the selection data.\n\t */\n\tprotected createFromAlias(\n\t\tentityTarget: EntityTarget<any> | ((qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>),\n\t\taliasName?: string,\n\t): Alias {\n\t\t// if table has a metadata then find it to properly escape its properties","sourceCodeStart":576,"sourceCodeEnd":612,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/QueryBuilder.ts#L576-L612","documentation":"QueryBuilder.getMainTableName() throws when expressionMap.mainAlias is null. For an INSERT, the main alias is set by .into(Entity); without it, the builder does not know which table to insert into. The guard fires during createInsertExpression() before any SQL is generated.","triggerScenarios":"Calling .insert().values(payload).execute() (or .getQuery()) without a preceding .into(Entity). Also when .into() is called with an unregistered entity so the alias has no metadata/tablePath.","commonSituations":"Chaining .insert().values(...) and forgetting .into(). Conditional code that skips .into() in a branch. Passing a non-entity to .into().","solutions":["Always call .into(Entity) before .values() on an insert builder.","Prefer dataSource.createQueryBuilder().insert().into(Entity).values(payload).","Use repository.insert(payload) which targets the repository's entity implicitly."],"exampleFix":"// before\nawait dataSource.createQueryBuilder()\n  .insert().values({ email }).execute(); // no .into()\n\n// after\nawait dataSource.createQueryBuilder()\n  .insert().into(User).values({ email }).execute();","handlingStrategy":"validation","validationCode":"function insertBuilderHasTarget(qb: { expressionMap: { mainAlias?: unknown } }): boolean {\n  return qb.expressionMap.mainAlias != null;\n}\nif (!insertBuilderHasTarget(qb)) throw new Error('call .into(Entity) before .values() on an insert builder');","typeGuard":"function hasIntoTarget(qb: { expressionMap: { mainAlias?: unknown } }): qb is { expressionMap: { mainAlias: { metadata: unknown } } } {\n  return qb.expressionMap.mainAlias != null;\n}","tryCatchPattern":null,"preventionTips":["Always call .into(Entity) before .values() on insert builders.","Prefer repository.insert(payload) which targets the entity implicitly.","Add a shared insert helper that enforces the into+values order.","Lint for .insert().values(...) without .into()."],"tags":["query-builder","insert","alias","setup"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}