dgraph-io/dgraph · error

found invalid nullint

Error message

found invalid nullint

What it means

For intType columns the driver returns sql.NullInt64; if its Valid flag is false the cell is a NULL integer. getValue treats this as unrecoverable and returns "found invalid nullint", mirroring the generic nil-value rejection but for the typed nullable wrapper.

Source

Thrown at dgraph/cmd/migrate/table_guide.go:161

func getCstColumns(cst *fkConstraint) map[string]interface{} {
	columnNames := make(map[string]interface{})
	for _, part := range cst.parts {
		columnNames[part.columnName] = struct{}{}
	}
	return columnNames
}

func getValue(dataType dataType, value interface{}) (string, error) {
	if value == nil {
		return "", errors.Errorf("nil value found")
	}

	switch dataType {
	case stringType:
		return fmt.Sprintf("%s", value), nil
	case intType:
		if !value.(sql.NullInt64).Valid {
			return "", errors.Errorf("found invalid nullint")
		}
		intVal, _ := value.(sql.NullInt64).Value()
		return fmt.Sprintf("%v", intVal), nil
	case datetimeType:
		if !value.(mysql.NullTime).Valid {
			return "", errors.Errorf("found invalid nulltime")
		}
		dateVal, _ := value.(mysql.NullTime).Value()
		return fmt.Sprintf("%v", dateVal), nil
	case floatType:
		if !value.(sql.NullFloat64).Valid {
			return "", errors.Errorf("found invalid nullfloat")
		}
		floatVal, _ := value.(sql.NullFloat64).Value()
		return fmt.Sprintf("%v", floatVal), nil
	default:
		return fmt.Sprintf("%v", value), nil
	}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Use COALESCE(col, 0) (or another sentinel) in the source query / clean NULLs in the table.
  2. Alter the column to NOT NULL DEFAULT 0 before migrating.
  3. Modify getValue to return an empty string for invalid NullInt64 if missing values are acceptable.
  4. Find the offending column via the wrapped "while dumping table X" context.

Example fix

// before
case intType:
	if !value.(sql.NullInt64).Valid {
		return "", errors.Errorf("found invalid nullint")
	}
// after
case intType:
	ni, _ := value.(sql.NullInt64)
	if !ni.Valid {
		return "", nil // skip NULL ints
	}
Defensive patterns

Strategy: validation

Validate before calling

-- find NULL ints in int-typed columns
SELECT id FROM orders WHERE qty IS NULL;

Type guard

func validInt(v interface{}) bool {
	ni, ok := v.(sql.NullInt64)
	return ok && ni.Valid
}

Try / catch

if err := migrate.Run(); err != nil {
	if strings.Contains(err.Error(), "found invalid nullint") {
		log.Printf("NULL int column detected: %+v", err)
	}
}

Prevention

When it happens

Trigger: A column typed as intType in the table guide contains SQL NULL (sql.NullInt64{Valid:false}) and is processed by outputPlainCell, generate, or createLabel during dumpTable.

Common situations: Nullable INT columns with NULL rows; data inserted before a NOT NULL constraint was added; ETL jobs writing NULLs into integer columns.

Related errors


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