{"record":{"id":"1a02f1dbadfd9b06","repo":"dgraph-io/dgraph","slug":"schema-not-defined-for-predicate-v","errorCode":null,"errorMessage":"Schema not defined for predicate: %v.","messagePattern":"Schema not defined for predicate: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/schema.go","lineNumber":281,"sourceCode":"// GetType gets the type definition for the given type name.\nfunc (s *state) GetType(typeName string) (pb.TypeUpdate, bool) {\n\ts.RLock()\n\tdefer s.RUnlock()\n\ttyp, has := s.types[typeName]\n\tif !has {\n\t\treturn pb.TypeUpdate{}, false\n\t}\n\treturn *typ, true\n}\n\n// TypeOf returns the schema type of predicate\nfunc (s *state) TypeOf(pred string) (types.TypeID, error) {\n\ts.RLock()\n\tdefer s.RUnlock()\n\tif schema, ok := s.predicate[pred]; ok {\n\t\treturn types.TypeID(schema.ValueType), nil\n\t}\n\treturn types.UndefinedID, errors.Errorf(\"Schema not defined for predicate: %v.\", pred)\n}\n\n// IsIndexed returns whether the predicate is indexed or not\nfunc (s *state) IsIndexed(ctx context.Context, pred string) bool {\n\tisWrite, _ := ctx.Value(IsWrite).(bool)\n\ts.RLock()\n\tdefer s.RUnlock()\n\tif isWrite {\n\t\t// TODO(Aman): we could return the query schema if it is a delete.\n\t\tif schema, ok := s.mutSchema[pred]; ok &&\n\t\t\t(len(schema.Tokenizer) > 0 || len(schema.IndexSpecs) > 0) {\n\t\t\treturn true\n\t\t}\n\t}\n\n\tif schema, ok := s.predicate[pred]; ok {\n\t\treturn len(schema.Tokenizer) > 0 || len(schema.IndexSpecs) > 0\n\t}","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/schema/schema.go#L263-L299","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nt, err := schema.TypeOf(\"emial\") // typo\n// after\n// ALTER schema: \"emial: string .\"  (or fix the name)\nt, err := schema.TypeOf(\"email\")","handlingStrategy":"try-catch","validationCode":"if schema.State() != nil {\n    if _, ok := schema.State().Predicate(pred); !ok {\n        return fmt.Errorf(\"predicate %q not in schema; apply ALTER first\", pred)\n    }\n}","typeGuard":null,"tryCatchPattern":"tid, err := schema.TypeOf(pred)\nif err != nil {\n    if strings.Contains(err.Error(), \"Schema not defined for predicate\") {\n        return applyAlterSchema(pred + \": string .\") // define then retry\n    }\n    return err\n}","preventionTips":["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"],"tags":["dgraph","schema","predicate","undefined"],"backgroundTag":"predicate-schema-not-defined","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}