{"record":{"id":"d9f12083381abf99","repo":"dgraph-io/dgraph","slug":"found-invalid-nullint","errorCode":null,"errorMessage":"found invalid nullint","messagePattern":"found invalid nullint","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/migrate/table_guide.go","lineNumber":161,"sourceCode":"func getCstColumns(cst *fkConstraint) map[string]interface{} {\n\tcolumnNames := make(map[string]interface{})\n\tfor _, part := range cst.parts {\n\t\tcolumnNames[part.columnName] = struct{}{}\n\t}\n\treturn columnNames\n}\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}","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/table_guide.go#L143-L179","documentation":"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.","triggerScenarios":"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.","commonSituations":"Nullable INT columns with NULL rows; data inserted before a NOT NULL constraint was added; ETL jobs writing NULLs into integer columns.","solutions":["Use COALESCE(col, 0) (or another sentinel) in the source query / clean NULLs in the table.","Alter the column to NOT NULL DEFAULT 0 before migrating.","Modify getValue to return an empty string for invalid NullInt64 if missing values are acceptable.","Find the offending column via the wrapped \"while dumping table X\" context."],"exampleFix":"// before\ncase intType:\n\tif !value.(sql.NullInt64).Valid {\n\t\treturn \"\", errors.Errorf(\"found invalid nullint\")\n\t}\n// after\ncase intType:\n\tni, _ := value.(sql.NullInt64)\n\tif !ni.Valid {\n\t\treturn \"\", nil // skip NULL ints\n\t}","handlingStrategy":"validation","validationCode":"-- find NULL ints in int-typed columns\nSELECT id FROM orders WHERE qty IS NULL;","typeGuard":"func validInt(v interface{}) bool {\n\tni, ok := v.(sql.NullInt64)\n\treturn ok && ni.Valid\n}","tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif strings.Contains(err.Error(), \"found invalid nullint\") {\n\t\tlog.Printf(\"NULL int column detected: %+v\", err)\n\t}\n}","preventionTips":["COALESCE NULL ints to a sentinel in the SELECT","Add NOT NULL DEFAULT 0 to integer columns before migrating","Normalize the driver value with sql.NullInt64 before conversion"],"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"}