siyuan-note/siyuan · error
--av, --name and --type are required
Error message
--av, --name and --type are required
What it means
The `database add-key` subcommand requires three flags together: `--av` (target database), `--name` (key name), and `--type` (key type). When any of the three is empty, RunE returns this combined error before creating anything. It enforces the minimal contract for defining a new database field.
Solutions
- Pass all three flags: `--av <avID> --name <keyName> --type <keyType>`
- Use a supported key type value (e.g. text, number, date, select, relation)
- Add `--icon`/`--prev` optionally for icon and position
- Validate with `--dry-run` first
Example fix
// before siyuan database add-key --av 20240101120000-avxyz --name "Priority" // after siyuan database add-key --av 20240101120000-avxyz --name "Priority" --type select
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$AV_ID" ] || [ -z "$KEY_NAME" ] || [ -z "$KEY_TYPE" ]; then echo "--av, --name and --type are required"; exit 1 fi siyuan database add-key --av "$AV_ID" --name "$KEY_NAME" --type "$KEY_TYPE"
Prevention
- Validate all three required values before invoking
- Check the --type against supported key types
- Always run --dry-run first for schema mutations
When it happens
Trigger: Running `siyuan database add-key` missing any of `--av`, `--name`, or `--type`, e.g. providing only the database ID.
Common situations: Forgetting `--type` (text, number, select, relation, etc.) because the name alone seems sufficient; scripts with an empty name variable; omitting `--av` in loops over multiple databases.
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 and --key are required
- --av is required
- --av, --key, --item and --value 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/ecc337a8727d8c6f.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/database.go:148
},
}
var databaseKeyCmd = &cobra.Command{
Use: "key",
Short: "Manage database keys (fields)",
}
var databaseKeyAddCmd = &cobra.Command{
Use: "add --av <avID> --name <name> --type <type>",
Short: "Add a key (field) to database",
RunE: func(cmd *cobra.Command, args []string) error {
avID, _ := cmd.Flags().GetString("av")
name, _ := cmd.Flags().GetString("name")
keyType, _ := cmd.Flags().GetString("type")
icon, _ := cmd.Flags().GetString("icon")
prev, _ := cmd.Flags().GetString("prev")
if avID == "" || name == "" || keyType == "" {
return fmt.Errorf("--av, --name and --type are required")
}
if dryRun {
fmt.Printf("[dry-run] Would add key \"%s\" (type=%s) to database %s\n", name, keyType, avID)
return nil
}
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{View on GitHub (pinned to 9f775e8a12)