{"record":{"id":"671be70dd6c1e0df","repo":"toeverything/AFFiNE","slug":"table-table-name-primary-key-field-table","errorCode":null,"errorMessage":"[Table(${table.name})]: Primary key field '${table.keyField}' is required but not set.","messagePattern":"\\[Table\\((.+?)\\)\\]: Primary key field '(.+?)' is required but not set\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/common/infra/src/orm/core/validators/data.ts","lineNumber":36,"sourceCode":"      case 'bigint':\n      case 'function':\n      case 'object': // we've already converted available types into 'json'\n      case 'symbol':\n      case 'undefined':\n        return false;\n    }\n  }\n\n  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];","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/infra/src/orm/core/validators/data.ts#L18-L54","documentation":"A data validator (PrimaryKeyShouldExist) run on insert/create paths: it fires when the record being written has its primary-key field (table.keyField) set to undefined or null. Every row must carry a primary key, so the faulting input is the data object passed to the ORM operation, which is missing table.keyField for the named table.","triggerScenarios":"Thrown at packages/common/infra/src/orm/core/validators/data.ts:36 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the primary key field on the entity before inserting it into the table.","Provide a default value provider for the key field in the schema if it should be generated.","Check the insert code path for a missing key assignment."],"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-14T00:17:10.932Z"}