{"record":{"id":"6208cc9d50598da0","repo":"siyuan-note/siyuan","slug":"block-is-required-for-non-detached-rows","errorCode":null,"errorMessage":"--block is required for non-detached rows","messagePattern":"--block is required for non-detached rows","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":253,"sourceCode":"}\n\nvar databaseItemAddCmd = &cobra.Command{\n\tUse:   \"add --av <avID>\",\n\tShort: \"Add a row to database\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tcontent, _ := cmd.Flags().GetString(\"content\")\n\t\tblockID, _ := cmd.Flags().GetString(\"block\")\n\t\tviewID, _ := cmd.Flags().GetString(\"view\")\n\t\tgroupID, _ := cmd.Flags().GetString(\"group\")\n\t\tpreviousID, _ := cmd.Flags().GetString(\"previous\")\n\t\tisDetached, _ := cmd.Flags().GetBool(\"detached\")\n\t\tignoreFill, _ := cmd.Flags().GetBool(\"ignore-default-fill\")\n\t\tif avID == \"\" {\n\t\t\treturn fmt.Errorf(\"--av is required\")\n\t\t}\n\t\tif !isDetached && blockID == \"\" {\n\t\t\treturn fmt.Errorf(\"--block is required for non-detached rows\")\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would add row to database %s\\n\", avID)\n\t\t\treturn nil\n\t\t}\n\n\t\tsrc := map[string]any{\n\t\t\t\"isDetached\": isDetached,\n\t\t}\n\t\tif blockID != \"\" {\n\t\t\tsrc[\"id\"] = blockID\n\t\t}\n\t\tif content != \"\" {\n\t\t\tsrc[\"content\"] = content\n\t\t}\n\t\tsrcs := []map[string]any{src}\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/database.go#L235-L271","documentation":"Thrown by the database row `add` command when `--av` is present, `--detached` is false (the default), and `--block` is empty. A non-detached row must bind to an existing block (`src[\"id\"] = blockID`), so a bound row without a block ID is invalid. Use `--detached` to create a row without a backing block.","triggerScenarios":"Running `siyuan database add --av <id> --content \"x\"` (detached defaults to false, block missing), intending a bound row but forgetting the block.","commonSituations":"Not realizing rows are bound by default, or intending a standalone row but forgetting `--detached`.","solutions":["If you want a standalone row, add `--detached`: `siyuan database add --av <id> --detached --content \"x\"`","If you want a bound row, supply the target block ID: `siyuan database add --av <id> --block <blockID>`","Confirm the block ID exists in the same workspace before binding"],"exampleFix":"// before\nsiyuan database add --av 20240101000000-av12345 --content \"task\"\n\n// after\nsiyuan database add --av 20240101000000-av12345 --detached --content \"task\"","handlingStrategy":"validation","validationCode":"if !isDetached && strings.TrimSpace(blockID) == \"\" {\n    log.Fatal(\"--block is required for non-detached rows (or pass --detached)\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to --detached unless you explicitly bind to a block","When binding, verify the block ID exists in the same workspace","Document the detached/bound distinction in your scripting helpers"],"tags":["cli","database","attribute-view","row","flag-validation","conditional-argument"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}