dgraph-io/dgraph · error

nil value found

Error message

nil value found

What it means

getValue converts a raw SQL cell into its string/RDF representation based on the column's dataType. It rejects nil cells outright with "nil value found" because the migrate tool has no policy for emitting NULL predicates/edges.

Source

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

					"when getting ref label: %+v\n", cst)
			}
			continue
		}
		r.refToBlank[refLabel] = blankNode
	}
}

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:

View on GitHub (pinned to 759e242be6)

Solutions

  1. Sanitize source data: replace NULLs with defaults (COALESCE) or exclude NULL rows in the SELECT.
  2. Make columns NOT NULL with a default before migrating.
  3. Patch table_guide.go to skip nil values instead of erroring if your use case tolerates missing predicates.
  4. Identify the offending column from the wrapped table context and clean it.

Example fix

// before
SELECT id, nickname FROM users; -- nickname NULL -> "nil value found"
// after
SELECT id, COALESCE(nickname, '') AS nickname FROM users;
Defensive patterns

Strategy: validation

Validate before calling

-- scan all columns for NULLs before migrating
SELECT COUNT(*) FROM users WHERE col1 IS NULL OR col2 IS NULL;

Type guard

// Go: guard before passing to converters
func isNullCell(v interface{}) bool { return v == nil }

Try / catch

if err := migrate.Run(); err != nil {
	if strings.Contains(err.Error(), "nil value found") {
		log.Printf("NULL cell in source data: %+v", err)
	}
}

Prevention

When it happens

Trigger: dumpTable reads a row whose column value is nil (SQL NULL) for any column type (string, int, datetime, float) and calls getValue on it via outputPlainCell, generate, or createLabel.

Common situations: Source tables contain NULLable columns with NULL rows; joins produce missing values; columns added later without defaults left legacy rows NULL.

Related errors


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