toeverything/AFFiNE · error · Error
[Table(${table.name})]: Primary key field '${table.keyField}
Error message
[Table(${table.name})]: Primary key field '${table.keyField}' can't be updated. What it means
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.
Source
Thrown at packages/common/infra/src/orm/core/validators/data.ts:45
return typeWant === typeGet;
}
export const dataValidators = {
PrimaryKeyShouldExist: {
validate(table, data) {
const val = data[table.keyField];
if (val === undefined || val === null) {
throw new Error(
`[Table(${table.name})]: Primary key field '${table.keyField}' is required but not set.`
);
}
},
},
PrimaryKeyShouldNotBeUpdated: {
validate(table, data) {
if (data[table.keyField] !== undefined) {
throw new Error(
`[Table(${table.name})]: Primary key field '${table.keyField}' can't be updated.`
);
}
},
},
DataTypeShouldMatch: {
validate(table, data) {
for (const key in data) {
const field = table.schema[key];
if (field) {
const val = data[key];
if (val === undefined) {
delete data[key];
continue;
}
if (val === null) {View on GitHub (pinned to b4c8548c09)
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/common/infra/src/orm/core/validators/data.ts:45 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18).
Data as JSON: /api/errors/079f43828b36772f.
Report an issue: GitHub.