dgraph-io/dgraph · error
while writing data file
Error message
while writing data file
What it means
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.
Source
Thrown at dgraph/cmd/migrate/run.go:172
schemaWriter, schemaCancelFunc, err := getFileWriter(schemaOutput)
if err != nil {
return err
}
defer schemaCancelFunc()
dataWriter, dataCancelFunc, err := getFileWriter(dataOutput)
if err != nil {
return err
}
defer dataCancelFunc()
dumpMeta.dataWriter = dataWriter
dumpMeta.schemaWriter = schemaWriter
if err := dumpMeta.dumpSchema(); err != nil {
return errors.Wrapf(err, "while writing schema file")
}
if err := dumpMeta.dumpTables(); err != nil {
return errors.Wrapf(err, "while writing data file")
}
return nil
}
View on GitHub (pinned to 759e242be6)
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.
Example fix
// before err := migrate.Run() // "while writing data file: while dumping table orders: nil value found" // after -- fix source: SELECT ... COALESCE(nullable_col, default) or clean NULLs, then rerun migrate
Defensive patterns
Strategy: try-catch
Validate before calling
if err := canWrite(filepath.Dir(dataPath)); err != nil {
return fmt.Errorf("cannot write data to %s: %w", dataPath, err)
}
// plus pre-dump data checks for NULLs and orphans (see errors 111/112) Type guard
func isDataWriteErr(err error) bool {
return strings.Contains(err.Error(), "while writing data file")
} Try / catch
if err := migrate.Run(); err != nil {
if isDataWriteErr(err) {
log.Printf("data phase failed, cause: %+v", errors.Cause(err))
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Mid-migration DB connection loss; bad row data (NULLs) in one table; unwritable/full disk for the data output file; orphaned foreign keys.
Related errors
- while writing schema
- while dumping table %s
- while writing schema file
- not allowed to overwrite %s
- nil value found
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/536e9b9cbc47198c.
Report an issue: GitHub.