siyuan-note/siyuan · error
cannot change field type to primary key
Error message
cannot change field type to primary key
What it means
Error "cannot change field type to primary key" thrown in siyuan-note/siyuan.
Source
Thrown at kernel/model/attribute_view.go:7173
attrView, err := av.ParseAttributeView(operation.AvID)
if err != nil {
return
}
colType := av.KeyType(operation.Typ)
changeType := false
switch colType {
case av.KeyTypeBlock, av.KeyTypeText, av.KeyTypeNumber, av.KeyTypeDate, av.KeyTypeSelect, av.KeyTypeMSelect, av.KeyTypeURL, av.KeyTypeEmail,
av.KeyTypePhone, av.KeyTypeMAsset, av.KeyTypeTemplate, av.KeyTypeCreated, av.KeyTypeUpdated, av.KeyTypeCheckbox,
av.KeyTypeRelation, av.KeyTypeRollup, av.KeyTypeLineNumber:
for _, keyValues := range attrView.KeyValues {
if keyValues.Key.ID == operation.ID {
isPrimaryKey := av.KeyTypeBlock == keyValues.Key.Type
if isPrimaryKey != (av.KeyTypeBlock == colType) {
if isPrimaryKey {
err = errors.New("cannot change type of primary key field")
} else {
err = errors.New("cannot change field type to primary key")
}
return
}
keyValues.Key.Name = strings.TrimSpace(operation.Name)
changeType = keyValues.Key.Type != colType
keyValues.Key.Type = colType
for _, value := range keyValues.Values {
value.Type = colType
}
break
}
}
}
View on GitHub (pinned to 251596fc0d)
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.
Example fix
Set the field type to a supported non-primary type such as text, number, date, or select instead of block/primary key.
When it happens
Trigger: Calling /api/av/updateAttributeViewKey (or the database field type menu) attempting to change a field's type to the primary key (block) type.
Common situations: 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.
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/142997b6b4548817.
Report an issue: GitHub.