siyuan-note/siyuan · error

cannot remove primary key field

Error message

cannot remove primary key field

What it means

Error "cannot remove primary key field" thrown in siyuan-note/siyuan.

Source

Thrown at kernel/model/attribute_view.go:7259

	if err != nil {
		return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}
	}
	return
}

func RemoveAttributeViewKey(avID, keyID string, removeRelationDest bool) (err error) {
	attrView, err := av.ParseAttributeView(avID)
	if err != nil {
		return
	}

	key, keyErr := attrView.GetKey(keyID)
	if nil != keyErr {
		err = keyErr
		return
	}
	if av.KeyTypeBlock == key.Type {
		err = errors.New("cannot remove primary key field")
		return
	}

	var removedKey *av.Key
	for i, keyValues := range attrView.KeyValues {
		if keyValues.Key.ID == keyID {
			attrView.KeyValues = append(attrView.KeyValues[:i], attrView.KeyValues[i+1:]...)
			removedKey = keyValues.Key
			attrView.RemoveNewItemTemplateFieldValue(keyID)
			break
		}
	}
	if nil != removedKey && av.KeyTypeRelation == removedKey.Type && nil != removedKey.Relation {
		if removedKey.Relation.IsTwoWay {
			var destAv *av.AttributeView
			if avID == removedKey.Relation.AvID {
				destAv = attrView
			} else {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Remove a non-primary field instead; every attribute view requires its primary key field.
  2. If the field is unwanted, hide it in the view rather than deleting it.

Example fix

In the database view, use 'Hide' on the primary field, or delete any other field by id.

When it happens

Trigger: Calling /api/av/removeAttributeViewKey or the UI delete-field action on the attribute view's primary key field.

Common situations: Occurs when the user tries to remove the primary key (block) field of an attribute view, either through the table header menu or the batch field-removal API.


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/8c52d9a69c8071d5. Report an issue: GitHub.