dgraph-io/dgraph · error

No schema found after namespace. Got: %v

Error message

No schema found after namespace. Got: %v

What it means

After consuming the namespace tokens, parseNamespace calls it.Next() and, if no further token exists, reports 'No schema found after namespace'. It means the schema ended immediately after the [ns] section with no predicate/type declarations following.

Source

Thrown at schema/parse.go:597

}

func parseNamespace(it *lex.ItemIterator) (uint64, error) {
	nextItems, err := it.Peek(2)
	if err != nil {
		return 0, errors.Errorf("Unable to peek: %v", err)
	}
	if nextItems[0].Typ != itemNumber || nextItems[1].Typ != itemRightSquare {
		return 0, errors.Errorf("Typed oes not match the expected")
	}
	ns, err := strconv.ParseUint(nextItems[0].Val, 0, 64)
	if err != nil {
		return 0, err
	}
	it.Next()
	it.Next()
	// We have parsed the namespace. Now move to the next item.
	if !it.Next() {
		return 0, errors.Errorf("No schema found after namespace. Got: %v", nextItems[0])
	}
	return ns, nil
}

// ParsedSchema represents the parsed schema and type updates.
type ParsedSchema struct {
	Preds []*pb.SchemaUpdate
	Types []*pb.TypeUpdate
}

func isTypeDeclaration(item lex.Item, it *lex.ItemIterator) bool {
	if item.Val != "type" {
		return false
	}

	nextItems, err := it.Peek(2)
	switch {
	case err != nil || len(nextItems) != 2:

View on GitHub (pinned to 759e242be6)

Solutions

  1. Include at least one predicate/type definition after the [ns] block, e.g. "name: string ."
  2. Do not send a schema update whose body is empty; skip the call entirely
  3. Validate the generated schema string is non-empty and contains ':' type lines before calling Parse

Example fix

// before
schema := "[0x1]\n"
// after
schema := "[0x1]\nname: string @index(exact) ."
Defensive patterns

Strategy: validation

Validate before calling

if !strings.Contains(strings.TrimPrefix(schemaStr, "[0x1]"), ":") && strings.HasPrefix(strings.TrimSpace(schemaStr), "[") {
    return fmt.Errorf("schema has namespace header but no predicate definitions")
}

Try / catch

if _, err := schema.Parse(s, 0, 1); err != nil {
    if strings.Contains(err.Error(), "No schema found after namespace") {
        return fmt.Errorf("empty schema body: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Passing a schema string that consists only of a namespace header, e.g. "[0x1]" or "[0x1]\n", to schema.Parse or ParseWithNamespace.

Common situations: Generating schema from a template where all predicates were filtered out, leaving only the namespace; empty drop-all-then-modify flows that post a schema with headers but no definitions; truncated multi-line schema files.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/32d3df12a9bf21e3. Report an issue: GitHub.