{"record":{"id":"e9eb1a110441408a","repo":"dgraph-io/dgraph","slug":"while-writing-schema","errorCode":null,"errorMessage":"while writing schema","messagePattern":"while writing schema","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/migrate/dump.go","lineNumber":60,"sourceCode":"// invalid sql queries in cases where a table uses a reserved keyword as a\n// column name\nfunc escapeColumnNames(columnNames []string) []string {\n\tvar escapedColNames []string\n\tfor _, c := range columnNames {\n\t\tescapedColNames = append(escapedColNames, fmt.Sprintf(\"`\"+\"%s\"+\"`\", c))\n\t}\n\treturn escapedColNames\n}\n\n// dumpSchema generates the Dgraph schema based on m.tableGuides\n// and sends the schema to m.schemaWriter\nfunc (m *dumpMeta) dumpSchema() error {\n\tfor table := range m.tableGuides {\n\t\ttableInfo := m.tableInfos[table]\n\t\tfor _, index := range createDgraphSchema(tableInfo) {\n\t\t\t_, err := m.schemaWriter.WriteString(index)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrapf(err, \"while writing schema\")\n\t\t\t}\n\t\t}\n\t}\n\treturn m.schemaWriter.Flush()\n}\n\n// dumpTables goes through all the tables twice. In the first time it generates RDF entries for the\n// column values. In the second time, it follows the foreign key constraints in SQL tables, and\n// generate the corresponding Dgraph edges.\nfunc (m *dumpMeta) dumpTables() error {\n\tfor table := range m.tableInfos {\n\t\tfmt.Printf(\"Dumping table %s\\n\", table)\n\t\tif err := m.dumpTable(table); err != nil {\n\t\t\treturn errors.Wrapf(err, \"while dumping table %s\", table)\n\t\t}\n\t}\n\n\tfor table := range m.tableInfos {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/dump.go#L42-L78","documentation":"dumpSchema iterates the SQL table guides, generates Dgraph schema predicate definitions via createDgraphSchema, and writes each line into m.schemaWriter (a bufio.Writer). The error is a pkg/errors.Wrapf of the underlying bufio/os write failure, so the original cause (disk full, closed writer, permissions) is chained in the wrapped error.","triggerScenarios":"m.schemaWriter.WriteString(index) fails while dumping schema for any table in m.tableGuides during dgraph migrate --schema/--data output generation; e.g. the output file was closed, the disk is full, or the writer's underlying file was deleted.","commonSituations":"Disk full on the node running the migration; output schema file path on a read-only or removed volume; running migrate with a schema file path that points at a directory; earlier code path (user declined overwrite at checkFile) leaving the file handle in a bad state.","solutions":["Check free disk space on the output volume and rerun the migration.","Verify the schema output path is writable and is a regular file, not a directory.","Inspect the chained cause with %+v on the returned error to see the original write failure.","Ensure no other process removed or truncated the schema file during the run."],"exampleFix":"// before\n_, err := m.schemaWriter.WriteString(index)\nif err != nil {\n\treturn errors.Wrapf(err, \"while writing schema\")\n}\n// after\nif _, err := m.schemaWriter.WriteString(index); err != nil {\n\treturn errors.Wrapf(err, \"while writing schema (check disk space / file permissions)\")\n}\nif err := m.schemaWriter.Flush(); err != nil {\n\treturn errors.Wrapf(err, \"while flushing schema writer\")\n}","handlingStrategy":"try-catch","validationCode":"// Go: before running migrate\nif fi, err := os.Stat(outPath); err == nil && fi.IsDir() {\n\treturn fmt.Errorf(\"schema output path %s is a directory\", outPath)\n}\nif err := checkDiskSpace(filepath.Dir(outPath), 100<<20); err != nil {\n\treturn err\n}","typeGuard":"func isWriteErr(err error) bool {\n\tvar pe *os.PathError\n\treturn errors.As(err, &pe)\n}","tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif strings.Contains(err.Error(), \"while writing schema\") {\n\t\tlog.Printf(\"schema write failed: %+v\", err) // full chain\n\t}\n}","preventionTips":["Pre-check free disk space before large migrations","Ensure output paths are writable regular files, not directories","Do not delete output files while migrate is running"],"tags":["io","migration","file-write"],"backgroundTag":"disk-full-write-failure","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}