{"record":{"id":"4bda4787470b8f54","repo":"remix-run/remix","slug":"onupdate-requires-references-to-be-set-first","errorCode":null,"errorMessage":"onUpdate() requires references() to be set first","messagePattern":"onUpdate\\(\\) requires references\\(\\) to be set first","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/data-table/src/lib/column.ts","lineNumber":154,"sourceCode":"   * @returns The column builder.\n   */\n  onDelete(action: ForeignKeyAction): ColumnBuilder<output> {\n    if (!this.#definition.references) {\n      throw new Error('onDelete() requires references() to be set first')\n    }\n\n    this.#definition.references.onDelete = action\n    return this\n  }\n\n  /**\n   * Sets the foreign-key action used when the referenced row is updated.\n   * @param action Update action to apply.\n   * @returns The column builder.\n   */\n  onUpdate(action: ForeignKeyAction): ColumnBuilder<output> {\n    if (!this.#definition.references) {\n      throw new Error('onUpdate() requires references() to be set first')\n    }\n\n    this.#definition.references.onUpdate = action\n    return this\n  }\n\n  /**\n   * Adds a check constraint for the column.\n   * @param expression SQL check expression.\n   * @param name Constraint name.\n   * @returns The column builder.\n   */\n  check(expression: string, name: string): ColumnBuilder<output> {\n    let checks = this.#definition.checks ?? []\n    checks.push({ expression, name })\n    this.#definition.checks = checks\n    return this\n  }","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/data-table/src/lib/column.ts#L136-L172","documentation":"ColumnBuilder.onUpdate(action) sets the foreign-key ON UPDATE action and, like onDelete, requires the references() configuration to exist first. Without a reference target there is no foreign key to configure, so the builder throws instead of silently ignoring the call.","triggerScenarios":"Calling .onUpdate('cascade') on a column builder that has not had .references() called.","commonSituations":"Schema refactors that lose the references() chain; mirror of the more common onDelete ordering mistake; copy-paste between columns where only some are foreign keys.","solutions":["Chain references() first: column.references(() => other.id).onUpdate('cascade').","Remove onUpdate() if the column is not meant to be a foreign key."],"exampleFix":"// before\nuserId: t.integer('user_id').onUpdate('cascade')\n\n// after\nuserId: t.integer('user_id').references(() => users.id).onUpdate('cascade')","handlingStrategy":"validation","validationCode":"// Always build foreign keys as one chained expression so references() precedes onUpdate()\nuserId: (t) => t.integer('user_id').references(() => users.id).onUpdate('cascade')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chain references() immediately after the column type method.","Add a schema smoke test that instantiates every table definition."],"tags":["schema","foreign-keys","column-builder","data-table"],"backgroundTag":"builder-method-order","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}