siyuan-note/siyuan · error
--av and --key are required
Error message
--av and --key are required
What it means
The `database remove-key` subcommand requires both `--av` (database ID) and `--key` (key/field ID). Either being empty returns this combined error before any removal. This guard prevents accidental unscoped deletions.
Solutions
- Fetch the key ID via `siyuan database keys --av <avID>` and pass it to `--key`
- Provide both flags: `--av <avID> --key <keyID>`
- Optionally set `--remove-relation-dest` to also clean relation destinations
- Use `--dry-run` before actual removal
Example fix
// before siyuan database remove-key --av 20240101120000-avxyz --key "Priority" // after siyuan database remove-key --av 20240101120000-avxyz --key 20240101120000-key1
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$AV_ID" ] || [ -z "$KEY_ID" ]; then echo "--av and --key are required"; exit 1 fi KEY_ID=$(siyuan database keys --av "$AV_ID" | resolve-id-of "$KEY_NAME") siyuan database remove-key --av "$AV_ID" --key "$KEY_ID"
Prevention
- Resolve key IDs via `database keys` instead of guessing from names
- Validate both flags for non-emptiness
- Use --dry-run before destructive removal
- Consider --remove-relation-dest implications beforehand
When it happens
Trigger: Running `siyuan database remove-key` without `--key`, without `--av`, or with both empty. Note `--key` must be the key ID, not the display name.
Common situations: Passing a human-readable field name to `--key` instead of its ID; forgetting `--av` when the key ID alone seems unique; automation scripts with unset variables.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- --av and --ids are required
- --av is required
- --av, --key, --item and --value are required
- --av, --name and --type are required
- --block is required for non-detached rows
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a3970f19c3dfed65.
Report an issue: GitHub.
Appendix: 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 9f775e8a12)