{"record":{"id":"142997b6b4548817","repo":"siyuan-note/siyuan","slug":"cannot-change-field-type-to-primary-key","errorCode":null,"errorMessage":"cannot change field type to primary key","messagePattern":"cannot change field type to primary key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view.go","lineNumber":7173,"sourceCode":"\tattrView, err := av.ParseAttributeView(operation.AvID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tcolType := av.KeyType(operation.Typ)\n\tchangeType := false\n\tswitch colType {\n\tcase av.KeyTypeBlock, av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail,\n\t\tav.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox,\n\t\tav.KeyTypeRelation, av.KeyTypeRollup, av.KeyTypeLineNumber:\n\t\tfor _, keyValues := range attrView.KeyValues {\n\t\t\tif keyValues.Key.ID == operation.ID {\n\t\t\t\tisPrimaryKey := av.KeyTypeBlock == keyValues.Key.Type\n\t\t\t\tif isPrimaryKey != (av.KeyTypeBlock == colType) {\n\t\t\t\t\tif isPrimaryKey {\n\t\t\t\t\t\terr = errors.New(\"cannot change type of primary key field\")\n\t\t\t\t\t} else {\n\t\t\t\t\t\terr = errors.New(\"cannot change field type to primary key\")\n\t\t\t\t\t}\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tkeyValues.Key.Name = strings.TrimSpace(operation.Name)\n\n\t\t\t\tchangeType = keyValues.Key.Type != colType\n\t\t\t\tkeyValues.Key.Type = colType\n\n\t\t\t\tfor _, value := range keyValues.Values {\n\t\t\t\t\tvalue.Type = colType\n\t\t\t\t}\n\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":7155,"sourceCodeEnd":7191,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/attribute_view.go#L7155-L7191","documentation":"Error \"cannot change field type to primary key\" thrown in siyuan-note/siyuan.","triggerScenarios":"Calling /api/av/updateAttributeViewKey (or the database field type menu) attempting to change a field's type to the primary key (block) type.","commonSituations":"Occurs when the user tries to change an attribute view field's type to the primary key (block) type via the API or the field settings UI; only the existing primary key may hold that type.","solutions":["Choose a different target type for the field; the primary key type is reserved for the attribute view's block key.","If you need a primary key, create a new attribute view or edit the existing primary key field instead."],"exampleFix":"Set the field type to a supported non-primary type such as text, number, date, or select instead of block/primary key.","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"}