{"record":{"id":"2138f6c9b9319cd2","repo":"remix-run/remix","slug":"create-returnrow-true-requires-primary-key-v","errorCode":null,"errorMessage":"create({ returnRow: true }) requires primary key values for table \"' + getTableName(table) + '\" when the database does not support RETURNING","messagePattern":"create\\((.+?)\\) requires primary key values for table \"' \\+ getTableName\\(table\\) \\+ '\" when the database does not support RETURNING","errorType":"exception","errorClass":"DataTableQueryError","httpStatus":null,"severity":"error","filePath":"packages/data-table/src/lib/database/helpers.ts","lineNumber":80,"sourceCode":"\n    if (Object.prototype.hasOwnProperty.call(values, key)) {\n      return {\n        [key]: (values as Record<string, unknown>)[key],\n      } as SingleTableWhere<table>\n    }\n\n    if (insertId !== undefined) {\n      return {\n        [key]: insertId,\n      } as SingleTableWhere<table>\n    }\n  }\n\n  let where: Record<string, unknown> = {}\n\n  for (let key of primaryKey) {\n    if (!Object.prototype.hasOwnProperty.call(values, key)) {\n      throw new DataTableQueryError(\n        'create({ returnRow: true }) requires primary key values for table \"' +\n          getTableName(table) +\n          '\" when the database does not support RETURNING',\n      )\n    }\n\n    where[key] = (values as Record<string, unknown>)[key]\n  }\n\n  return where as SingleTableWhere<table>\n}\n\nexport function normalizeOrderByInput<table extends AnyTable>(\n  input: OrderByInput<table> | undefined,\n): OrderByTuple<table>[] {\n  if (!input) {\n    return []\n  }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table/src/lib/database/helpers.ts#L62-L98","documentation":"When you call create() with returnRow: true on a database that does not support the SQL RETURNING clause (e.g. older SQLite or MySQL), the library must re-select the inserted row by its primary key. If the values you passed do not include every primary key column, there is no way to locate the row afterwards, so a DataTableQueryError is thrown listing the missing requirement. Supply all primary key values or drop returnRow.","triggerScenarios":"create({ values, returnRow: true }) where values omits one or more primary key columns, while database.capabilities.returning is false (MySQL, SQLite without RETURNING).","commonSituations":"Using auto-increment integer primary keys and assuming the database/client generates them, but the table's primary key is client-provided; switching an app from Postgres (RETURNING supported) to MySQL/SQLite without adding PK values; composite primary keys where only part is provided.","solutions":["Include every primary key column value in the create() call, e.g. values: { id: crypto.randomUUID(), ...data }","Remove returnRow: true if you don't need the row back and rely on the returned id instead","Switch to a database or driver whose capabilities.returning is true (e.g. Postgres, SQLite 3.35+ with RETURNING enabled)"],"exampleFix":"// before\nlet row = await table.create({\n  values: { email: 'a@b.com' },\n  returnRow: true,\n})\n\n// after\nlet row = await table.create({\n  values: { id: crypto.randomUUID(), email: 'a@b.com' },\n  returnRow: true,\n})","handlingStrategy":"validation","validationCode":"let missing = primaryKeyColumns.filter(k => !(k in values))\nif (missing.length > 0 && options?.returnRow && !capabilities.returning) {\n  throw new Error('Provide PK values: ' + missing.join(', '))\n}","typeGuard":"function canCreateWithReturnRow(values: Record<string, unknown>, primaryKey: string[], capabilities: { returning: boolean }): boolean {\n  return capabilities.returning || primaryKey.every((key) => key in values)\n}","tryCatchPattern":"try {\n  row = await table.create({ values, returnRow: true })\n} catch (error) {\n  if (error instanceof DataTableQueryError && /primary key values/.test(error.message)) {\n    row = await table.row({ where: { id: values.id } }) // after adding id\n  } else throw error\n}","preventionTips":["Always generate client-side ids (crypto.randomUUID()) for create() calls that use returnRow","Branch on database.capabilities.returning when supporting multiple databases","Cover create-with-returnRow paths in integration tests against every database you support"],"tags":["data-table","create","primary-key","returning","database-capabilities"],"backgroundTag":"missing-primary-key-on-insert-returning","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}