{"record":{"id":"8c52d9a69c8071d5","repo":"siyuan-note/siyuan","slug":"cannot-remove-primary-key-field","errorCode":null,"errorMessage":"cannot remove primary key field","messagePattern":"cannot remove primary key field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":7259,"sourceCode":"\tif err != nil {\n\t\treturn &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}\n\t}\n\treturn\n}\n\nfunc RemoveAttributeViewKey(avID, keyID string, removeRelationDest bool) (err error) {\n\tattrView, err := av.ParseAttributeView(avID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tkey, keyErr := attrView.GetKey(keyID)\n\tif nil != keyErr {\n\t\terr = keyErr\n\t\treturn\n\t}\n\tif av.KeyTypeBlock == key.Type {\n\t\terr = errors.New(\"cannot remove primary key field\")\n\t\treturn\n\t}\n\n\tvar removedKey *av.Key\n\tfor i, keyValues := range attrView.KeyValues {\n\t\tif keyValues.Key.ID == keyID {\n\t\t\tattrView.KeyValues = append(attrView.KeyValues[:i], attrView.KeyValues[i+1:]...)\n\t\t\tremovedKey = keyValues.Key\n\t\t\tattrView.RemoveNewItemTemplateFieldValue(keyID)\n\t\t\tbreak\n\t\t}\n\t}\n\tif nil != removedKey && av.KeyTypeRelation == removedKey.Type && nil != removedKey.Relation {\n\t\tif removedKey.Relation.IsTwoWay {\n\t\t\tvar destAv *av.AttributeView\n\t\t\tif avID == removedKey.Relation.AvID {\n\t\t\t\tdestAv = attrView\n\t\t\t} else {","sourceCodeStart":7241,"sourceCodeEnd":7277,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L7241-L7277","documentation":"Error \"cannot remove primary key field\" thrown in siyuan-note/siyuan.","triggerScenarios":"Calling /api/av/removeAttributeViewKey or the UI delete-field action on the attribute view's primary key field.","commonSituations":"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.","solutions":["Remove a non-primary field instead; every attribute view requires its primary key field.","If the field is unwanted, hide it in the view rather than deleting it."],"exampleFix":"In the database view, use 'Hide' on the primary field, or delete any other field by id.","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}