{"record":{"id":"536e9b9cbc47198c","repo":"dgraph-io/dgraph","slug":"while-writing-data-file","errorCode":null,"errorMessage":"while writing data file","messagePattern":"while writing data file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/migrate/run.go","lineNumber":172,"sourceCode":"\tschemaWriter, schemaCancelFunc, err := getFileWriter(schemaOutput)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer schemaCancelFunc()\n\tdataWriter, dataCancelFunc, err := getFileWriter(dataOutput)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer dataCancelFunc()\n\n\tdumpMeta.dataWriter = dataWriter\n\tdumpMeta.schemaWriter = schemaWriter\n\n\tif err := dumpMeta.dumpSchema(); err != nil {\n\t\treturn errors.Wrapf(err, \"while writing schema file\")\n\t}\n\tif err := dumpMeta.dumpTables(); err != nil {\n\t\treturn errors.Wrapf(err, \"while writing data file\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":154,"sourceCodeEnd":176,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/run.go#L154-L176","documentation":"In generateSchemaAndData, the error returned by dumpTables (either its row-dump pass or its constraints pass) is re-wrapped with \"while writing data file\", indicating the data output phase failed. Both inner passes already add \"while dumping table <name>\" context, producing a full wrap chain to the root cause.","triggerScenarios":"dumpTables returns any error: SQL read failure on a table, NULL/invalid value conversion via getValue, orphaned FK during constraint resolution, or dataWriter Flush failure.","commonSituations":"Mid-migration DB connection loss; bad row data (NULLs) in one table; unwritable/full disk for the data output file; orphaned foreign keys.","solutions":["Print with %+v and read the chain: data file phase -> while dumping table X -> root cause.","Fix the specific table's data or DB connectivity issue named in the chain.","Check disk space/writability for the --data output path.","Rerun the migration after fixing; remove/overwrite the partial output files."],"exampleFix":"// before\nerr := migrate.Run()  // \"while writing data file: while dumping table orders: nil value found\"\n// after\n-- fix source: SELECT ... COALESCE(nullable_col, default) or clean NULLs, then rerun migrate","handlingStrategy":"try-catch","validationCode":"if err := canWrite(filepath.Dir(dataPath)); err != nil {\n\treturn fmt.Errorf(\"cannot write data to %s: %w\", dataPath, err)\n}\n// plus pre-dump data checks for NULLs and orphans (see errors 111/112)","typeGuard":"func isDataWriteErr(err error) bool {\n\treturn strings.Contains(err.Error(), \"while writing data file\")\n}","tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif isDataWriteErr(err) {\n\t\tlog.Printf(\"data phase failed, cause: %+v\", errors.Cause(err))\n\t}\n}","preventionTips":["Clean NULLs and orphaned FKs before migrating","Monitor DB connection stability for long dumps","Read the full wrap chain with %+v to find the failing table"],"tags":["io","migration","data-conversion"],"backgroundTag":"sql-dump-table-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}