dgraph-io/dgraph · error

Schema does not contain a matching predicate for field %s in

Error message

Schema does not contain a matching predicate for field %s in type %s

What it means

verifyTypes requires every field of every type being updated to correspond to a predicate that either already exists in the schema or is being created in the same request. This error is returned when a type field's predicate is found neither in the fetched schema (schemaSet) nor in the predicates attached to the current request (reqPredSet). In short: the type references a predicate Dgraph does not know about.

Source

Thrown at worker/mutation.go:808

	schemaSet := make(map[string]struct{})
	for _, schemaNode := range schemas {
		schemaSet[schemaNode.Predicate] = struct{}{}
	}

	for _, t := range m.Types {
		// Verify all the fields in the type are already on the schema or come included in
		// this request.
		for _, field := range t.Fields {
			fieldName := field.Predicate
			ns, attr := x.ParseNamespaceAttr(fieldName)
			if attr[0] == '~' {
				fieldName = x.NamespaceAttr(ns, attr[1:])
			}

			_, inSchema := schemaSet[fieldName]
			_, inRequest := reqPredSet[fieldName]
			if !inSchema && !inRequest {
				return errors.Errorf(
					"Schema does not contain a matching predicate for field %s in type %s",
					field.Predicate, t.TypeName)
			}
		}
	}

	return nil
}

// typeSanityCheck performs basic sanity checks on the given type update.
func typeSanityCheck(t *pb.TypeUpdate) error {
	for _, field := range t.Fields {
		if x.ParseAttr(field.Predicate) == "" {
			return errors.Errorf("Field in type definition must have a name")
		}

		if field.ValueType == pb.Posting_OBJECT && field.ObjectTypeName == "" {
			return errors.Errorf(

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add the missing predicate to the schema first (e.g. `email: string @index(exact) .`) or include its SchemaUpdate in the same request so reqPredSet contains it
  2. Check the field name for typos against dgraph's schema output (curl localhost:8080/state or the schema query)
  3. Update or remove the type definition if the predicate was intentionally deleted
  4. When using namespaces, ensure the field carries the correct namespace qualifier so the resolved name matches the stored predicate

Example fix

// before: type references a predicate that does not exist
type Person {
  emial
}

// after: define the predicate first, then the type
email: string @index(exact) .
type Person {
  email
}
Defensive patterns

Strategy: validation

Validate before calling

// Fetch current schema and verify every type field exists before mutating
schemaResp, _ := client.Query(ctx, "schema {}")
known := map[string]bool{}
for _, p := range parsePredicates(schemaResp) {
	known[p] = true
}
for _, t := range mutation.Types {
	for _, f := range t.Fields {
		if !known[f.Predicate] {
			return fmt.Errorf("predicate %q in type %q not in schema; add it first", f.Predicate, t.TypeName)
		}
	}
}

Type guard

func predicatesDefined(t *api.TypeUpdate, known map[string]bool) bool {
	for _, f := range t.Fields {
		if !known[f.Predicate] {
			return false
		}
	}
	return true
}

Try / catch

_, err := txn.Mutate(ctx, mu)
if err != nil && strings.Contains(err.Error(), "does not contain a matching predicate") {
	// extract field/type from the message and add the missing predicate to the schema first
	return fmt.Errorf("define the missing predicate in the schema before updating types: %w", err)
}

Prevention

When it happens

Trigger: Sending a mutation whose types block declares a field (e.g. `type Person { email }`) while the schema contains no `email` predicate and the same mutation/schema update does not define it; a typo in a field name (emial vs email); dropping a predicate in one request while a type still references it.

Common situations: Renaming predicates without updating type definitions; schema migration scripts that add types before the predicates; typos in DQL type blocks; deleting predicates via /alter while types keep referencing them; namespace-prefixed fields (@name handling via x.NamespaceAttr) referenced without the correct namespace prefix.

Related errors


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