{"record":{"id":"a3970f19c3dfed65","repo":"siyuan-note/siyuan","slug":"av-and-key-are-required","errorCode":null,"errorMessage":"--av and --key are required","messagePattern":"--av and --key are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":174,"sourceCode":"\t\tkeyID := ast.NewNodeID()\n\t\tif err := model.AddAttributeViewKey(avID, \"\", keyID, name, keyType, icon, prev, av.DateDisplayFormatFull); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(keyID)\n\t\treturn nil\n\t},\n}\n\nvar databaseKeyRemoveCmd = &cobra.Command{\n\tUse:   \"remove --av <avID> --key <keyID>\",\n\tShort: \"Remove a key (field) from database\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tkeyID, _ := cmd.Flags().GetString(\"key\")\n\t\tremoveRelation, _ := cmd.Flags().GetBool(\"remove-relation-dest\")\n\t\tif avID == \"\" || keyID == \"\" {\n\t\t\treturn fmt.Errorf(\"--av and --key are required\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would remove key %s from database %s\\n\", keyID, avID)\n\t\t\treturn nil\n\t\t}\n\n\t\tif err := model.RemoveAttributeViewKey(avID, keyID, removeRelation); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar databaseUnusedCmd = &cobra.Command{\n\tUse:   \"unused\",","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/database.go#L156-L192","documentation":"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.","triggerScenarios":"Running `siyuan database key remove --av <id>` without `--key`, or omitting both.","commonSituations":"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.","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"],"exampleFix":"// before\nsiyuan database key remove --av 20240101000000-av12345\n\n// after\nsiyuan database key remove --av 20240101000000-av12345 --key 20240101000000-key1234","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(avID) == \"\" || strings.TrimSpace(keyID) == \"\" {\n    log.Fatal(\"--av and --key are required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","database","attribute-view","key","flag-validation","argument-required"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}