siyuan-note/siyuan · error

parent ID is required

Error message

parent ID is required

What it means

CreateAttributeViewDatabase requires a parent block ID so it knows which document/container to insert the new database block into. When parentID is the empty string, there is no valid insertion target, so the function immediately returns this error before doing any work.

Source

Thrown at kernel/model/attribute_view_create.go:52

type AttributeViewCreateKey struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Icon string `json:"icon,omitempty"`
}

// AttributeViewCreateResult 描述创建数据库后可供调用方继续操作的标识和数据。
type AttributeViewCreateResult struct {
	BlockID       string
	AvID          string
	ViewID        string
	AttributeView *av.AttributeView
}

// CreateAttributeViewDatabase 创建数据库块和对应属性视图,并按照 keySpecs 的顺序初始化字段。
func CreateAttributeViewDatabase(parentID, previousID, nextID, name, primaryKeyName string, layout av.LayoutType,
	keySpecs []*AttributeViewCreateKey) (ret *AttributeViewCreateResult, err error) {
	if "" == parentID {
		return nil, errors.New("parent ID is required")
	}
	if "" != previousID && "" != nextID {
		return nil, errors.New("previous ID and next ID cannot both be specified")
	}
	if "" == previousID && "" == nextID {
		if err = treenode.CheckContainerParent(parentID); nil != err {
			return nil, err
		}
	}
	if "" == layout {
		layout = av.LayoutTypeTable
	}
	switch layout {
	case av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:
	default:
		return nil, av.ErrWrongLayoutType
	}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Obtain a valid parent block ID first (e.g. the document ID or a container block ID) and pass it as parentID
  2. If inserting relative to a sibling block, use that sibling's parent as parentID and pass the sibling as previousID/nextID
  3. Validate the parent ID is non-empty in the caller before invoking the API

Example fix

// before
ret, err := model.CreateAttributeViewDatabase("", "", nextID, "DB", "Name", av.LayoutTypeTable, keys)
// after
if parentID == "" {
    return errors.New("resolve a parent block ID first")
}
ret, err := model.CreateAttributeViewDatabase(parentID, "", nextID, "DB", "Name", av.LayoutTypeTable, keys)
Defensive patterns

Strategy: validation

Validate before calling

if parentID == "" {
    return errors.New("cannot create database: parent ID is empty")
}

Prevention

When it happens

Trigger: Calling CreateAttributeViewDatabase (or the databaseCreate API route) with parentID="" — typically because the caller never resolved the document/block ID from a UI selection, or passed an uninitialized variable.

Common situations: Plugin or script automation that creates a database without first obtaining a document ID; a frontend call where the user had no focused document so the parent ID field was never populated; copying example code that omits parentID.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/6af61f5c922f334a. Report an issue: GitHub.