dgraph-io/dgraph · error
index for predicate [ ] is missing, add int index with…
Error message
index for predicate [%v] is missing, add int index with @unique
What it means
Int predicates marked @unique must be indexed with the 'int' tokenizer. When validateSchemaForUnique sees an int predicate with an empty tokenizer list, it rejects the schema because Dgraph cannot enforce uniqueness over an unindexed int predicate.
Solutions
- Add the int index: `employeeId int @index(int) @unique .` and re-run the alter.
- Remove @unique if uniqueness enforcement is not needed.
- Verify with /state or the schema endpoint that the predicate now shows the int tokenizer.
Example fix
// before (fails) employeeId int @unique . // after employeeId int @index(int) @unique .
Defensive patterns
Strategy: validation
Validate before calling
# int predicates: @unique requires @index(int)
for pred in schemaChanges:
if pred.unique and pred.type == 'int' and 'int' not in (pred.index or []):
raise ValueError(f"{pred.name}: add @index(int) with @unique") Try / catch
// Go client
if err := dg.Alter(ctx, op); err != nil {
if strings.Contains(err.Error(), "add int index") {
// rewrite schema: <pred> int @index(int) @unique . and retry
}
} Prevention
- Treat @unique on int as shorthand that still demands @index(int).
- Keep schema definitions in version control and lint for unique-without-index.
When it happens
Trigger: Altering the schema to add @unique to an int predicate that has no @index(int) directive, e.g. `age int @unique .` with no tokenizer. Raised by checkSchema -> validateSchemaForUnique.
Common situations: Declaring a unique employee ID or external numeric key as `@unique` without remembering Dgraph (unlike some databases) requires the index to be spelled out; migrating schemas from SQL where unique implies its own index.
Related errors
- index for predicate [ ] is missing, add either hash or…
- Attribute: does not have proper index for comparison
- Attribute is not indexed.
- could not drop index
- Directive must be SchemaUpdate_INDEX when a tokenizer is…
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/c54b220812dfc429.
Report an issue: GitHub.
Appendix: source
Thrown at worker/mutation.go:495
}
}
if !currentSchema.Upsert {
currentSchema.Upsert = true
}
switch currentSchema.ValueType {
case pb.Posting_STRING:
if len(currentSchema.Tokenizer) == 0 ||
(len(currentSchema.Tokenizer) > 0 && !validTokenizer(currentSchema.Tokenizer)) {
return errors.Errorf("index for predicate [%v] is missing, add either hash or exact index with @unique",
x.ParseAttr(currentSchema.Predicate))
} else {
return nil
}
case pb.Posting_INT:
if len(currentSchema.Tokenizer) == 0 {
return errors.Errorf("index for predicate [%v] is missing, add int index with @unique",
x.ParseAttr(currentSchema.Predicate))
} else {
return nil
}
}
return errors.Errorf("@unique directive not supported on [%v] type predicate", currentSchema.ValueType.String())
}
// ValidateAndConvert checks compatibility or converts to the schema type if the storage type is
// specified. If no storage type is specified then it converts to the schema type.
func ValidateAndConvert(edge *pb.DirectedEdge, su *pb.SchemaUpdate) error {
if isDeletePredicateEdge(edge) {
return nil
}
if types.TypeID(edge.ValueType) == types.DefaultID && isStarAll(edge.Value) {
return nilView on GitHub (pinned to 759e242be6)