{"record":{"id":"3979249fa258ac1e","repo":"remix-run/remix","slug":"create-returnrow-true-failed-to-load-inserte","errorCode":null,"errorMessage":"create({ returnRow: true }) failed to load inserted row","messagePattern":"create\\((.+?)\\) failed to load inserted row","errorType":"exception","errorClass":"DataTableQueryError","httpStatus":null,"severity":"error","filePath":"packages/data-table/src/lib/database.ts","lineNumber":596,"sourceCode":"\n      if (!row) {\n        throw new DataTableQueryError(\n          'create({ returnRow: true }) failed to return an inserted row',\n        )\n      }\n\n      if (!options.with) {\n        return row as TableRowWith<table, LoadedRelationMap<relations>>\n      }\n\n      let where = getPrimaryKeyWhereFromRow(table, row)\n      let loaded = await this.findOne(table, {\n        where,\n        with: options.with,\n      })\n\n      if (!loaded) {\n        throw new DataTableQueryError('create({ returnRow: true }) failed to load inserted row')\n      }\n\n      return loaded\n    }\n\n    let insertResult = await query.insert(values, { touch })\n    let where = resolveCreateRowWhere(table, values, toWriteResult(insertResult).insertId)\n    let loaded = await this.findOne(table, {\n      where,\n      with: options.with,\n    })\n\n    if (!loaded) {\n      throw new DataTableQueryError('create({ returnRow: true }) failed to load inserted row')\n    }\n\n    return loaded\n  }","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table/src/lib/database.ts#L578-L614","documentation":"With returnRow: true and relations to load (options.with), create() first inserts, then re-fetches the row with findOne to hydrate relations. If that findOne returns nothing — the row vanished between insert and select — this error is thrown. Typically caused by triggers, default scopes, or a where built from a returned row that doesn't match stored data.","triggerScenarios":"db.create(table, values, { returnRow: true, with: {...} }) where the subsequent findOne (using a primary-key where from the inserted row) finds no row: BEFORE INSERT triggers rewriting keys, RLS policies, or generated/rewritten primary keys the driver doesn't round-trip.","commonSituations":"SQLite triggers (e.g. rowid tables with conflicting INTEGER PRIMARY KEY aliasing) changing the stored row; databases where the driver fails to obtain the real key; row-level security filtering the re-select.","solutions":["Verify no trigger/policy rewrites or hides the inserted row; test the same insert+select manually.","Omit `with` (fetch relations in a second explicit findOne you control) to isolate whether hydration or insert is at fault.","If it persists, drop returnRow and load the row manually with an explicit where you know matches stored data."],"exampleFix":"// before\nlet row = await db.create(users, values, { returnRow: true, with: { posts: true } })\n\n// after\nlet { id } = await db.create(users, values)\nlet row = await db.findOne(users, (q) => q.where(eq(users.id, id)).with({ posts: true }))","handlingStrategy":"fallback","validationCode":"// Prefer explicit keys when hydrating relations after create\nlet result = await db.create(table, values)\nlet row = await db.findOne(table, primaryKeyWhere(table, result))","typeGuard":null,"tryCatchPattern":"try {\n  return await db.create(t, v, { returnRow: true, with })\n} catch (error) {\n  if (error instanceof DataTableQueryError && /failed to load/.test(error.message)) {\n    // fall back to a manual find with a known-good where\n  }\n}","preventionTips":["Supply explicit primary keys when tables have triggers.","Audit triggers/RLS on tables used with returnRow + with."],"tags":["data-table","insert","relations","returning"],"backgroundTag":"row-not-found-after-write","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}