siyuan-note/siyuan · error
--av and --key are required
Error message
--av and --key are required
What it means
Thrown by `database key remove` when `--av` or `--key` is empty. Removing a field needs both the database ID and the key (field) ID to pass to `model.RemoveAttributeViewKey`. The `--remove-relation-dest` bool is optional and not part of this guard.
Source
Thrown at kernel/cli/cmd/database.go:174
keyID := ast.NewNodeID()
if err := model.AddAttributeViewKey(avID, "", keyID, name, keyType, icon, prev, av.DateDisplayFormatFull); err != nil {
return err
}
model.AppendPushReloadAttrViewEntry(avID)
fmt.Println(keyID)
return nil
},
}
var databaseKeyRemoveCmd = &cobra.Command{
Use: "remove --av <avID> --key <keyID>",
Short: "Remove a key (field) from database",
RunE: func(cmd *cobra.Command, args []string) error {
avID, _ := cmd.Flags().GetString("av")
keyID, _ := cmd.Flags().GetString("key")
removeRelation, _ := cmd.Flags().GetBool("remove-relation-dest")
if avID == "" || keyID == "" {
return fmt.Errorf("--av and --key are required")
}
if dryRun {
fmt.Printf("[dry-run] Would remove key %s from database %s\n", keyID, avID)
return nil
}
if err := model.RemoveAttributeViewKey(avID, keyID, removeRelation); err != nil {
return err
}
model.AppendPushReloadAttrViewEntry(avID)
fmt.Println("ok")
return nil
},
}
var databaseUnusedCmd = &cobra.Command{
Use: "unused",View on GitHub (pinned to 251596fc0d)
Solutions
- List keys first with `siyuan database keys --av <id> --output json` to obtain each field's ID
- Pass both: `siyuan database key remove --av <avID> --key <keyID>`
- Use `--dry-run` to preview the removal before mutating
Example fix
// before siyuan database key remove --av 20240101000000-av12345 // after siyuan database key remove --av 20240101000000-av12345 --key 20240101000000-key1234
Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(avID) == "" || strings.TrimSpace(keyID) == "" {
log.Fatal("--av and --key are required")
} Prevention
- List keys with database keys --output json to copy the key ID (not name)
- Use --dry-run to confirm the key targets the intended field
When it happens
Trigger: Running `siyuan database key remove --av <id>` without `--key`, or omitting both.
Common situations: Confusing the key ID with the key name (the command wants the field's internal ID, not its display name), or not knowing where to find it.
Related errors
- --av, --name and --type are required
- --av is required
- --av and --ids are required
- --block is required for non-detached rows
- --av, --key, --item and --value are required
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/a3970f19c3dfed65.
Report an issue: GitHub.