{"record":{"id":"c5f001b0cbdcbcda","repo":"dgraph-io/dgraph","slug":"schema-does-not-contain-a-matching-predicate-for-f","errorCode":null,"errorMessage":"Schema does not contain a matching predicate for field %s in type %s","messagePattern":"Schema does not contain a matching predicate for field (.+?) in type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":808,"sourceCode":"\tschemaSet := make(map[string]struct{})\n\tfor _, schemaNode := range schemas {\n\t\tschemaSet[schemaNode.Predicate] = struct{}{}\n\t}\n\n\tfor _, t := range m.Types {\n\t\t// Verify all the fields in the type are already on the schema or come included in\n\t\t// this request.\n\t\tfor _, field := range t.Fields {\n\t\t\tfieldName := field.Predicate\n\t\t\tns, attr := x.ParseNamespaceAttr(fieldName)\n\t\t\tif attr[0] == '~' {\n\t\t\t\tfieldName = x.NamespaceAttr(ns, attr[1:])\n\t\t\t}\n\n\t\t\t_, inSchema := schemaSet[fieldName]\n\t\t\t_, inRequest := reqPredSet[fieldName]\n\t\t\tif !inSchema && !inRequest {\n\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\"Schema does not contain a matching predicate for field %s in type %s\",\n\t\t\t\t\tfield.Predicate, t.TypeName)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// typeSanityCheck performs basic sanity checks on the given type update.\nfunc typeSanityCheck(t *pb.TypeUpdate) error {\n\tfor _, field := range t.Fields {\n\t\tif x.ParseAttr(field.Predicate) == \"\" {\n\t\t\treturn errors.Errorf(\"Field in type definition must have a name\")\n\t\t}\n\n\t\tif field.ValueType == pb.Posting_OBJECT && field.ObjectTypeName == \"\" {\n\t\t\treturn errors.Errorf(","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L790-L826","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Check the field name for typos against dgraph's schema output (curl localhost:8080/state or the schema query)","Update or remove the type definition if the predicate was intentionally deleted","When using namespaces, ensure the field carries the correct namespace qualifier so the resolved name matches the stored predicate"],"exampleFix":"// before: type references a predicate that does not exist\ntype Person {\n  emial\n}\n\n// after: define the predicate first, then the type\nemail: string @index(exact) .\ntype Person {\n  email\n}","handlingStrategy":"validation","validationCode":"// Fetch current schema and verify every type field exists before mutating\nschemaResp, _ := client.Query(ctx, \"schema {}\")\nknown := map[string]bool{}\nfor _, p := range parsePredicates(schemaResp) {\n\tknown[p] = true\n}\nfor _, t := range mutation.Types {\n\tfor _, f := range t.Fields {\n\t\tif !known[f.Predicate] {\n\t\t\treturn fmt.Errorf(\"predicate %q in type %q not in schema; add it first\", f.Predicate, t.TypeName)\n\t\t}\n\t}\n}","typeGuard":"func predicatesDefined(t *api.TypeUpdate, known map[string]bool) bool {\n\tfor _, f := range t.Fields {\n\t\tif !known[f.Predicate] {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","tryCatchPattern":"_, err := txn.Mutate(ctx, mu)\nif err != nil && strings.Contains(err.Error(), \"does not contain a matching predicate\") {\n\t// extract field/type from the message and add the missing predicate to the schema first\n\treturn fmt.Errorf(\"define the missing predicate in the schema before updating types: %w\", err)\n}","preventionTips":["Always add predicate definitions before (or in the same request as) type definitions","Diff type definitions against `schema {}` output in CI before deploying","After deleting predicates, update all types that referenced them","Watch for typos and namespace prefixes when naming fields"],"tags":["schema","validation","dql","types"],"backgroundTag":"predicate-not-in-schema","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}