{"record":{"id":"079f43828b36772f","repo":"toeverything/AFFiNE","slug":"table-table-name-primary-key-field-table-079f43","errorCode":null,"errorMessage":"[Table(${table.name})]: Primary key field '${table.keyField}' can't be updated.","messagePattern":"\\[Table\\((.+?)\\)\\]: Primary key field '(.+?)' can't be updated\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/infra/src/orm/core/validators/data.ts","lineNumber":45,"sourceCode":"  return typeWant === typeGet;\n}\n\nexport const dataValidators = {\n  PrimaryKeyShouldExist: {\n    validate(table, data) {\n      const val = data[table.keyField];\n\n      if (val === undefined || val === null) {\n        throw new Error(\n          `[Table(${table.name})]: Primary key field '${table.keyField}' is required but not set.`\n        );\n      }\n    },\n  },\n  PrimaryKeyShouldNotBeUpdated: {\n    validate(table, data) {\n      if (data[table.keyField] !== undefined) {\n        throw new Error(\n          `[Table(${table.name})]: Primary key field '${table.keyField}' can't be updated.`\n        );\n      }\n    },\n  },\n  DataTypeShouldMatch: {\n    validate(table, data) {\n      for (const key in data) {\n        const field = table.schema[key];\n        if (field) {\n          const val = data[key];\n\n          if (val === undefined) {\n            delete data[key];\n            continue;\n          }\n\n          if (val === null) {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/infra/src/orm/core/validators/data.ts#L27-L63","documentation":"A data validator (PrimaryKeyShouldNotBeUpdated) run on update paths: it fires when the update payload contains a value for table.keyField (anything other than undefined). Primary keys are immutable in this ORM, so the faulting input is the update data object that attempts to change the primary-key field of the named table.","triggerScenarios":"Thrown at packages/common/infra/src/orm/core/validators/data.ts:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not modify the primary key of an existing record; delete and re-insert with the new key instead.","Remove the key field from update payloads.","Fix the update logic so it only touches mutable fields."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}