dgraph-io/dgraph · error
found invalid nulltime
Error message
found invalid nulltime
What it means
For datetimeType columns the go-sql-driver returns mysql.NullTime; when Valid is false the cell is a NULL timestamp. getValue returns "found invalid nulltime" rather than emitting an empty/invalid datetime predicate.
Source
Thrown at dgraph/cmd/migrate/table_guide.go:167
}
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
}
}
type ref struct {
allColumns map[string]*columnInfo
refColumnIndices []*columnIdx
tableName stringView on GitHub (pinned to 759e242be6)
Solutions
- Replace NULLs in the query with COALESCE(col, '1970-01-01 00:00:01') or filter out NULL rows.
- Set a NOT NULL DEFAULT on the datetime column before migrating.
- Patch getValue to skip invalid NullTime values if absent timestamps are acceptable in Dgraph.
- Locate the offending column from the wrapped table name in the error chain.
Example fix
// before SELECT id, completed_at FROM tasks; -- completed_at NULL // after SELECT id, COALESCE(completed_at, '1970-01-01 00:00:01') AS completed_at FROM tasks;
Defensive patterns
Strategy: validation
Validate before calling
-- find NULL datetimes in datetime-typed columns SELECT id FROM tasks WHERE completed_at IS NULL;
Type guard
func validTime(v interface{}) bool {
nt, ok := v.(mysql.NullTime)
return ok && nt.Valid
} Try / catch
if err := migrate.Run(); err != nil {
if strings.Contains(err.Error(), "found invalid nulltime") {
log.Printf("NULL datetime column detected: %+v", err)
}
} Prevention
- COALESCE NULL timestamps to an epoch default in the query
- Set NOT NULL DEFAULT on datetime columns
- Check mysql.NullTime.Valid before using the time value
When it happens
Trigger: A column mapped to datetimeType in the table guide contains SQL NULL (mysql.NullTime{Valid:false}) and is read during dumpTable via outputPlainCell, generate, or createLabel.
Common situations: Nullable TIMESTAMP/DATETIME columns (e.g. optional deleted_at, completed_at) with NULL rows; legacy rows predating a column addition; imports that left timestamps unset.
Related errors
- nil value found
- found invalid nullint
- while dumping table %s
- while writing schema
- not allowed to overwrite %s
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/000686a55d5e394b.
Report an issue: GitHub.