dgraph-io/dgraph · warning
not allowed to overwrite %s
Error message
not allowed to overwrite %s
What it means
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.
Source
Thrown at dgraph/cmd/migrate/run.go:137
}, schemaOutput, dataOutput)
}
// checkFile checks if the program is trying to output to an existing file.
// If so, we would need to ask the user whether we should overwrite the file or abort the program.
func checkFile(file string) error {
if _, err := os.Stat(file); err == nil {
// The file already exists.
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("overwriting the file %s (y/N)? ", file)
text, err := reader.ReadString('\n')
if err != nil {
return err
}
text = strings.TrimSpace(text)
if len(text) == 0 || strings.ToLower(text) == "n" {
return errors.Errorf("not allowed to overwrite %s", file)
}
if strings.ToLower(text) == "y" {
return nil
}
fmt.Println("Please type y or n (hit enter to choose n)")
}
}
// The file does not exist.
return nil
}
// generateSchemaAndData opens the two files schemaOutput and dataOutput,
// then it dumps schema to the writer backed by schemaOutput, and data in RDF format
// to the writer backed by dataOutput
func generateSchemaAndData(dumpMeta *dumpMeta, schemaOutput string, dataOutput string) error {
schemaWriter, schemaCancelFunc, err := getFileWriter(schemaOutput)
if err != nil {View on GitHub (pinned to 759e242be6)
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.
Example fix
// before dgraph migrate --data out.json ... # out.json exists, prompt answered 'n' // after rm out.json && dgraph migrate --data out.json ...
Defensive patterns
Strategy: validation
Validate before calling
# shell: ensure output files don't exist before running migrate
[ ! -e out.json ] || { mv out.json out.json.bak.$(date +%s); }
dgraph migrate --data out.json ... Try / catch
if err := migrate.Run(); err != nil {
if strings.Contains(err.Error(), "not allowed to overwrite") {
// rotate or rename the output file and retry
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- Key size value is too large (x > 4096)
- Key size value must be a factor of 2
- Elliptic curve value must be one of: P224, P256, P384 or P52
- Unsupported certificate
- Unsupported file
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/5ad549f42694e08e.
Report an issue: GitHub.