siyuan-note/siyuan · error

--block is required for non-detached rows

Error message

--block is required for non-detached rows

What it means

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.

Source

Thrown at kernel/cli/cmd/database.go:253

}

var databaseItemAddCmd = &cobra.Command{
	Use:   "add --av <avID>",
	Short: "Add a row to database",
	RunE: func(cmd *cobra.Command, args []string) error {
		avID, _ := cmd.Flags().GetString("av")
		content, _ := cmd.Flags().GetString("content")
		blockID, _ := cmd.Flags().GetString("block")
		viewID, _ := cmd.Flags().GetString("view")
		groupID, _ := cmd.Flags().GetString("group")
		previousID, _ := cmd.Flags().GetString("previous")
		isDetached, _ := cmd.Flags().GetBool("detached")
		ignoreFill, _ := cmd.Flags().GetBool("ignore-default-fill")
		if avID == "" {
			return fmt.Errorf("--av is required")
		}
		if !isDetached && blockID == "" {
			return fmt.Errorf("--block is required for non-detached rows")
		}

		if dryRun {
			fmt.Printf("[dry-run] Would add row to database %s\n", avID)
			return nil
		}

		src := map[string]any{
			"isDetached": isDetached,
		}
		if blockID != "" {
			src["id"] = blockID
		}
		if content != "" {
			src["content"] = content
		}
		srcs := []map[string]any{src}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. If you want a standalone row, add `--detached`: `siyuan database add --av <id> --detached --content "x"`
  2. If you want a bound row, supply the target block ID: `siyuan database add --av <id> --block <blockID>`
  3. Confirm the block ID exists in the same workspace before binding

Example fix

// before
siyuan database add --av 20240101000000-av12345 --content "task"

// after
siyuan database add --av 20240101000000-av12345 --detached --content "task"
Defensive patterns

Strategy: validation

Validate before calling

if !isDetached && strings.TrimSpace(blockID) == "" {
    log.Fatal("--block is required for non-detached rows (or pass --detached)")
}

Prevention

When it happens

Trigger: Running `siyuan database add --av <id> --content "x"` (detached defaults to false, block missing), intending a bound row but forgetting the block.

Common situations: Not realizing rows are bound by default, or intending a standalone row but forgetting `--detached`.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/6208cc9d50598da0. Report an issue: GitHub.