toeverything/AFFiNE · error · Error

[Table( )]: Field ' ' is required but not set.

Error message

[Table(${table.name})]: Field '${key}' is required but not set.

What it means

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.

Solutions

  1. Set the required field on the entity before saving.
  2. Add a default value provider in the schema if the field can be auto-filled.
  3. Check the data construction code for a missing assignment.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/common/infra/src/orm/core/validators/data.ts:65 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/12e9680052d1f85f. Report an issue: GitHub.

Appendix: source

Thrown at packages/common/infra/src/orm/core/validators/data.ts:65

        );
      }
    },
  },
  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) {
            if (!field.optional) {
              throw new Error(
                `[Table(${table.name})]: Field '${key}' is required but not set.`
              );
            }
            continue;
          }

          const typeGet = inputType(val);

          if (field.type === 'enum') {
            if (!field.values?.includes(val)) {
              throw new Error(
                `[Table(${table.name})]: Field '${key}' value '${val}' is not valid. Expected one of [${field.values?.join(', ')}].`
              );
            }
          } else if (!typeMatches(field.type, typeGet)) {
            throw new Error(
              `[Table(${table.name})]: Field '${key}' type mismatch. Expected ${field.type} got ${typeGet}.`
            );

View on GitHub (pinned to b4c8548c09)