{"record":{"id":"12e9680052d1f85f","repo":"toeverything/AFFiNE","slug":"table-table-name-field-key-is-required","errorCode":null,"errorMessage":"[Table(${table.name})]: Field '${key}' is required but not set.","messagePattern":"\\[Table\\((.+?)\\)\\]: 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":65,"sourceCode":"        );\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) {\n            if (!field.optional) {\n              throw new Error(\n                `[Table(${table.name})]: Field '${key}' is required but not set.`\n              );\n            }\n            continue;\n          }\n\n          const typeGet = inputType(val);\n\n          if (field.type === 'enum') {\n            if (!field.values?.includes(val)) {\n              throw new Error(\n                `[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`\n              );\n            }\n          } else if (!typeMatches(field.type, typeGet)) {\n            throw new Error(\n              `[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.`\n            );","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/packages/common/infra/src/orm/core/validators/data.ts#L47-L83","documentation":"A DataTypeShouldMatch validator case: while iterating the fields of the incoming data it encounters a null value for a schema field that is not marked optional. It fires on insert/update when a required (non-optional) field is explicitly set to null; the faulting input is the data object whose field 'key' of the named table is null while the schema requires it.","triggerScenarios":"Thrown at packages/common/infra/src/orm/core/validators/data.ts:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the required field on the entity before saving.","Add a default value provider in the schema if the field can be auto-filled.","Check the data construction code for a missing 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-14T05:17:10.506Z"}