{"record":{"id":"000686a55d5e394b","repo":"dgraph-io/dgraph","slug":"found-invalid-nulltime","errorCode":null,"errorMessage":"found invalid nulltime","messagePattern":"found invalid nulltime","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/migrate/table_guide.go","lineNumber":167,"sourceCode":"}\n\nfunc getValue(dataType dataType, value interface{}) (string, error) {\n\tif value == nil {\n\t\treturn \"\", errors.Errorf(\"nil value found\")\n\t}\n\n\tswitch dataType {\n\tcase stringType:\n\t\treturn fmt.Sprintf(\"%s\", value), nil\n\tcase intType:\n\t\tif !value.(sql.NullInt64).Valid {\n\t\t\treturn \"\", errors.Errorf(\"found invalid nullint\")\n\t\t}\n\t\tintVal, _ := value.(sql.NullInt64).Value()\n\t\treturn fmt.Sprintf(\"%v\", intVal), nil\n\tcase datetimeType:\n\t\tif !value.(mysql.NullTime).Valid {\n\t\t\treturn \"\", errors.Errorf(\"found invalid nulltime\")\n\t\t}\n\t\tdateVal, _ := value.(mysql.NullTime).Value()\n\t\treturn fmt.Sprintf(\"%v\", dateVal), nil\n\tcase floatType:\n\t\tif !value.(sql.NullFloat64).Valid {\n\t\t\treturn \"\", errors.Errorf(\"found invalid nullfloat\")\n\t\t}\n\t\tfloatVal, _ := value.(sql.NullFloat64).Value()\n\t\treturn fmt.Sprintf(\"%v\", floatVal), nil\n\tdefault:\n\t\treturn fmt.Sprintf(\"%v\", value), nil\n\t}\n}\n\ntype ref struct {\n\tallColumns       map[string]*columnInfo\n\trefColumnIndices []*columnIdx\n\ttableName        string","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/table_guide.go#L149-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nSELECT id, completed_at FROM tasks; -- completed_at NULL\n// after\nSELECT id, COALESCE(completed_at, '1970-01-01 00:00:01') AS completed_at FROM tasks;","handlingStrategy":"validation","validationCode":"-- find NULL datetimes in datetime-typed columns\nSELECT id FROM tasks WHERE completed_at IS NULL;","typeGuard":"func validTime(v interface{}) bool {\n\tnt, ok := v.(mysql.NullTime)\n\treturn ok && nt.Valid\n}","tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif strings.Contains(err.Error(), \"found invalid nulltime\") {\n\t\tlog.Printf(\"NULL datetime column detected: %+v\", err)\n\t}\n}","preventionTips":["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"],"tags":["migration","sql","null-value"],"backgroundTag":"unexpected-null-value","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}