dgraph-io/dgraph · error

index for predicate [%v] is missing, add int index with @uni

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.

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 nil

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add the int index: `employeeId int @index(int) @unique .` and re-run the alter.
  2. Remove @unique if uniqueness enforcement is not needed.
  3. 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

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


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