{"record":{"id":"5ad549f42694e08e","repo":"dgraph-io/dgraph","slug":"not-allowed-to-overwrite-s","errorCode":null,"errorMessage":"not allowed to overwrite %s","messagePattern":"not allowed to overwrite (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"dgraph/cmd/migrate/run.go","lineNumber":137,"sourceCode":"\t}, schemaOutput, dataOutput)\n}\n\n// checkFile checks if the program is trying to output to an existing file.\n// If so, we would need to ask the user whether we should overwrite the file or abort the program.\nfunc checkFile(file string) error {\n\tif _, err := os.Stat(file); err == nil {\n\t\t// The file already exists.\n\t\treader := bufio.NewReader(os.Stdin)\n\t\tfor {\n\t\t\tfmt.Printf(\"overwriting the file %s (y/N)? \", file)\n\t\t\ttext, err := reader.ReadString('\\n')\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\ttext = strings.TrimSpace(text)\n\n\t\t\tif len(text) == 0 || strings.ToLower(text) == \"n\" {\n\t\t\t\treturn errors.Errorf(\"not allowed to overwrite %s\", file)\n\t\t\t}\n\t\t\tif strings.ToLower(text) == \"y\" {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tfmt.Println(\"Please type y or n (hit enter to choose n)\")\n\t\t}\n\t}\n\n\t// The file does not exist.\n\treturn nil\n}\n\n// generateSchemaAndData opens the two files schemaOutput and dataOutput,\n// then it dumps schema to the writer backed by schemaOutput, and data in RDF format\n// to the writer backed by dataOutput\nfunc generateSchemaAndData(dumpMeta *dumpMeta, schemaOutput string, dataOutput string) error {\n\tschemaWriter, schemaCancelFunc, err := getFileWriter(schemaOutput)\n\tif err != nil {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/migrate/run.go#L119-L155","documentation":"checkFile prompts the user when the output file already exists and asks whether to overwrite. If the user presses enter or types anything other than 'y', checkFile deliberately returns this error to abort the migration instead of destroying the existing file.","triggerScenarios":"Running dgraph migrate (non-interactive or attended) with an --data/--schema path whose file already exists, and the operator answers 'n' or just hits enter at the overwrite prompt.","commonSituations":"Rerunning a migration after a previous attempt; CI/non-TTY environments where the prompt auto-defaults to n; user unsure and presses enter (defaults to no).","solutions":["Choose a new output file path, or delete/move the existing file first.","If overwrite is intended, answer 'y' at the prompt.","For automation, pre-remove the output files (rm data.json schema.txt) before invoking migrate so no prompt appears.","Note the error is intentional protection, not a bug."],"exampleFix":"// before\ndgraph migrate --data out.json ...  # out.json exists, prompt answered 'n'\n// after\nrm out.json && dgraph migrate --data out.json ...","handlingStrategy":"validation","validationCode":"# shell: ensure output files don't exist before running migrate\n[ ! -e out.json ] || { mv out.json out.json.bak.$(date +%s); }\ndgraph migrate --data out.json ...","typeGuard":null,"tryCatchPattern":"if err := migrate.Run(); err != nil {\n\tif strings.Contains(err.Error(), \"not allowed to overwrite\") {\n\t\t// rotate or rename the output file and retry\n\t}\n}","preventionTips":["Use unique/timestamped output file names per run","In CI, delete or archive prior output files before migrate","Don't rely on the interactive prompt in non-TTY environments — it defaults to no"],"tags":["cli","file-conflict","migration"],"backgroundTag":"file-already-exists","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}