{"record":{"id":"efc387bc98eba533","repo":"n8n-io/n8n","slug":"cannot-perform-insert-query-because-values-are-not","errorCode":null,"errorMessage":"Cannot perform insert query because values are not defined. Call \"qb.values(...)\" method to specify inserted values.","messagePattern":"Cannot perform insert query because values are not defined\\. Call \"qb\\.values\\(\\.\\.\\.\\)\" method to specify inserted values\\.","errorType":"exception","errorClass":"InsertValuesMissingError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/query-builder/InsertQueryBuilder.ts","lineNumber":720,"sourceCode":"\t\t\t\t\t} else {\n\t\t\t\t\t\texpression += ', ';\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t});\n\t\t\tif (expression === '()') return '';\n\t\t\treturn expression;\n\t\t}\n\t}\n\n\t/**\n\t * Gets array of values need to be inserted into the target table.\n\t */\n\tprotected getValueSets(): ObjectLiteral[] {\n\t\tif (Array.isArray(this.expressionMap.valuesSet)) return this.expressionMap.valuesSet;\n\n\t\tif (ObjectUtils.isObject(this.expressionMap.valuesSet)) return [this.expressionMap.valuesSet];\n\n\t\tthrow new InsertValuesMissingError();\n\t}\n\n\t/**\n\t * Checks if column is an auto-generated primary key, but the current insertion specifies a value for it.\n\t *\n\t * @param column\n\t */\n\tprotected isOverridingAutoIncrementBehavior(column: ColumnMetadata): boolean {\n\t\treturn (\n\t\t\tcolumn.isPrimary &&\n\t\t\tcolumn.isGenerated &&\n\t\t\tcolumn.generationStrategy === 'increment' &&\n\t\t\tthis.getValueSets().some(\n\t\t\t\t(valueSet) =>\n\t\t\t\t\tcolumn.getEntityValue(valueSet) !== undefined && column.getEntityValue(valueSet) !== null,\n\t\t\t)\n\t\t);\n\t}","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/query-builder/InsertQueryBuilder.ts#L702-L738","documentation":"InsertQueryBuilder.getValueSets() throws InsertValuesMissingError when expressionMap.valuesSet is neither an array nor a plain object (it is undefined/null). This means .values(...) was never called, so there is nothing to insert. The guard runs during query creation, before SQL is emitted.","triggerScenarios":"Calling insert().into(Entity).execute() (or .getQuery()) without a preceding .values({...}). Also when .values() is called with undefined, e.g. a variable that resolved to undefined at runtime.","commonSituations":"Building an insert conditionally and skipping the values call in an edge case. Passing an optional request body field that is undefined. Refactoring that removes the values line but leaves the insert chain.","solutions":["Always call .values(objectOrArray) between .into() and .execute().","Guard the insert behind a truthiness check on the payload before chaining.","Default the payload to an empty object and validate required fields separately if you want a no-op to be explicit.","Use repository.insert(payload) which surfaces the same requirement more clearly."],"exampleFix":"// before\nawait dataSource.createQueryBuilder()\n  .insert().into(User) // .values(...) missing\n  .execute();\n\n// after\nif (!payload) throw new Error('payload required');\nawait dataSource.createQueryBuilder()\n  .insert().into(User).values(payload)\n  .execute();","handlingStrategy":"validation","validationCode":"function hasInsertPayload(values: unknown): values is object | object[] {\n  return values != null && (Array.isArray(values) ? values.length > 0 : typeof values === 'object');\n}\nif (!hasInsertPayload(payload)) throw new Error('insert payload is required');","typeGuard":"function isNonEmptyInsertPayload(v: unknown): v is object | object[] {\n  if (Array.isArray(v)) return v.length > 0 && v.every(x => x && typeof x === 'object');\n  return v != null && typeof v === 'object';\n}","tryCatchPattern":null,"preventionTips":["Always chain .values(payload) after .into() on insert builders.","Guard the insert behind a truthiness check on the payload.","Prefer repository.insert(payload) for clarity.","Add a runtime assertion in shared insert helpers that payload is non-null."],"tags":["query-builder","insert","validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}