dgraph-io/dgraph · error
Schema not defined for predicate: %v.
Error message
Schema not defined for predicate: %v.
What it means
TypeOf looks up a predicate in the current in-memory schema state and returns types.UndefinedID with this error when the predicate has no schema entry. It means the caller asked for the type of a predicate that has never been defined in Dgraph's schema.
Source
Thrown at schema/schema.go:281
// GetType gets the type definition for the given type name.
func (s *state) GetType(typeName string) (pb.TypeUpdate, bool) {
s.RLock()
defer s.RUnlock()
typ, has := s.types[typeName]
if !has {
return pb.TypeUpdate{}, false
}
return *typ, true
}
// TypeOf returns the schema type of predicate
func (s *state) TypeOf(pred string) (types.TypeID, error) {
s.RLock()
defer s.RUnlock()
if schema, ok := s.predicate[pred]; ok {
return types.TypeID(schema.ValueType), nil
}
return types.UndefinedID, errors.Errorf("Schema not defined for predicate: %v.", pred)
}
// IsIndexed returns whether the predicate is indexed or not
func (s *state) IsIndexed(ctx context.Context, pred string) bool {
isWrite, _ := ctx.Value(IsWrite).(bool)
s.RLock()
defer s.RUnlock()
if isWrite {
// TODO(Aman): we could return the query schema if it is a delete.
if schema, ok := s.mutSchema[pred]; ok &&
(len(schema.Tokenizer) > 0 || len(schema.IndexSpecs) > 0) {
return true
}
}
if schema, ok := s.predicate[pred]; ok {
return len(schema.Tokenizer) > 0 || len(schema.IndexSpecs) > 0
}View on GitHub (pinned to 759e242be6)
Solutions
- Add the predicate to the schema (ALTER with 'pred: type .') before querying/mutating it
- Verify the predicate name spelling matches the schema exactly (case-sensitive)
- Confirm you are connected to the instance/namespace where the schema was applied
- Reload schema state (restart or re-fetch) if the predicate was recently created
Example fix
// before
t, err := schema.TypeOf("emial") // typo
// after
// ALTER schema: "emial: string ." (or fix the name)
t, err := schema.TypeOf("email") Defensive patterns
Strategy: try-catch
Validate before calling
if schema.State() != nil {
if _, ok := schema.State().Predicate(pred); !ok {
return fmt.Errorf("predicate %q not in schema; apply ALTER first", pred)
}
} Try / catch
tid, err := schema.TypeOf(pred)
if err != nil {
if strings.Contains(err.Error(), "Schema not defined for predicate") {
return applyAlterSchema(pred + ": string .") // define then retry
}
return err
} Prevention
- Define schema for every predicate before writing/querying it
- Validate predicate names against the fetched schema (/state or ALTER listing)
- Recheck schema after DropAll/DropAttr operations
- Watch for case-sensitivity and namespace mismatches in predicate names
When it happens
Trigger: Calling schema.TypeOf(pred) (or code paths using it, e.g. type coercion during mutations/queries) with a predicate name that was never added via alter/schema, or a typo in the predicate name, or querying before schema loading completes.
Common situations: Typos like 'friends' vs 'friend'; schema applied to a different namespace/instance than the one queried; race after DropAll/DropData clearing the schema while queries still run; JSON mutations inferring predicates before schema is loaded.
Related errors
- illegal rune found "%c", expecting {
- JSON map is followed by illegal rune "%c"
- Malformed JSON
- error creating indexer for %s: %w
- namespace: %d. No tablet found for: %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/1a02f1dbadfd9b06.
Report an issue: GitHub.