siyuan-note/siyuan · error

database field name and type are required

Error message

database field name and type are required

What it means

Each field spec in keySpecs must carry a non-blank name and a non-blank type string, which newAttributeViewKey later maps to a concrete av.Key type. A nil spec, or a spec whose name/type is empty or whitespace-only, cannot produce a valid field, so the whole creation aborts.

Source

Thrown at kernel/model/attribute_view_create.go:74

	}
	if "" == previousID && "" == nextID {
		if err = treenode.CheckContainerParent(parentID); nil != err {
			return nil, err
		}
	}
	if "" == layout {
		layout = av.LayoutTypeTable
	}
	switch layout {
	case av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:
	default:
		return nil, av.ErrWrongLayoutType
	}

	preparedKeys := make([]*av.Key, 0, len(keySpecs))
	for _, spec := range keySpecs {
		if nil == spec || "" == strings.TrimSpace(spec.Name) || "" == strings.TrimSpace(spec.Type) {
			return nil, errors.New("database field name and type are required")
		}
		key, keyErr := newAttributeViewKey(ast.NewNodeID(), strings.TrimSpace(spec.Name), strings.TrimSpace(spec.Type), spec.Icon,
			av.DateDisplayFormatFull)
		if nil != keyErr {
			return nil, keyErr
		}
		preparedKeys = append(preparedKeys, key)
	}

	blockID, avID := ast.NewNodeID(), ast.NewNodeID()
	data := fmt.Sprintf(`<div class="av" data-node-id="%s" data-av-id="%s" data-type="NodeAttributeView" data-av-type="%s"></div>`,
		blockID, avID, layout)
	operation := &Operation{
		Action:     "insert",
		Data:       data,
		ParentID:   parentID,
		PreviousID: previousID,
		NextID:     nextID,

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Ensure every spec has a trimmed, non-empty Name and a valid type string (e.g. "text", "number", "select", "date")
  2. Filter out nil or blank specs before building the slice
  3. Validate specs in the caller (or API handler) and return a clearer message about which field row is bad

Example fix

// before
specs := append(specs, &model.AttributeViewCreateKey{Name: userEnteredName, Type: userEnteredType}) // may be blank
// after
if strings.TrimSpace(userEnteredName) != "" && strings.TrimSpace(userEnteredType) != "" {
    specs = append(specs, &model.AttributeViewCreateKey{Name: strings.TrimSpace(userEnteredName), Type: strings.TrimSpace(userEnteredType)})
}
Defensive patterns

Strategy: validation

Validate before calling

for i, spec := range keySpecs {
    if spec == nil || strings.TrimSpace(spec.Name) == "" || strings.TrimSpace(spec.Type) == "" {
        return fmt.Errorf("keySpecs[%d]: name and type are required", i)
    }
}

Prevention

When it happens

Trigger: Passing a nil element in the keySpecs slice, or a spec with Name=""/" " or Type=""/" " to CreateAttributeViewDatabase.

Common situations: Building keySpecs programmatically from user input where an empty row slipped in; a mapping layer that emits specs for optional fields even when the user left them blank; typo where the type field was assigned to the wrong struct member.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/4f75edea58141268. Report an issue: GitHub.