{"record":{"id":"f85a1e7b91058294","repo":"gastownhall/beads","slug":"workspace-already-initialized-as-database-q-but","errorCode":null,"errorMessage":"workspace already initialized as database %q, but --database %q was requested.\nRemove --database (or pass a matching value) to reuse the existing workspace","messagePattern":"workspace already initialized as database %q, but --database %q was requested\\.\nRemove --database \\(or pass a matching value\\) to reuse the existing workspace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":783,"sourceCode":"\t\t// engdocs/adr/0002-init-safety-invariants.md).\n\t\tif !reinitLocal {\n\t\t\tif err := checkExistingBeadsData(prefix); err != nil {\n\t\t\t\t// --init-if-missing makes init idempotent, but ONLY for the\n\t\t\t\t// benign \"workspace already initialized\" case. An operational\n\t\t\t\t// error from the check (e.g. an unreadable .beads/embeddeddolt\n\t\t\t\t// directory) must still abort rather than be masked as a\n\t\t\t\t// successful skip.\n\t\t\t\tif initIfMissing && errors.Is(err, errWorkspaceAlreadyInitialized) {\n\t\t\t\t\t// Guard against masking a genuine mismatch: an explicit\n\t\t\t\t\t// --prefix or --database that does not match the existing\n\t\t\t\t\t// workspace must abort, since silently skipping would ignore\n\t\t\t\t\t// the request and reuse a different database. --database is\n\t\t\t\t\t// the authoritative selector, so it is checked even when\n\t\t\t\t\t// --prefix is also set.\n\t\t\t\t\texisting := existingWorkspaceDBName()\n\t\t\t\t\tif cmd.Flags().Changed(\"database\") {\n\t\t\t\t\t\tif initIfMissingDatabaseMismatch(existing, database) {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"workspace already initialized as database %q, but --database %q was requested.\\nRemove --database (or pass a matching value) to reuse the existing workspace\", existing, database)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if cmd.Flags().Changed(\"prefix\") {\n\t\t\t\t\t\tif initIfMissingPrefixMismatch(existing, prefix) {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"workspace already initialized as database %q, but --prefix %q was requested.\\nRemove --prefix (or pass a matching value) to reuse the existing workspace\", existing, prefix)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif !quiet {\n\t\t\t\t\t\tfmt.Fprintln(os.Stderr, \"Skipping init: workspace already initialized.\")\n\t\t\t\t\t}\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"%v\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Check BEADS_DB environment variable if --db flag not set\n\t\t// (PersistentPreRun doesn't run for init command)\n\t\tif dbPath == \"\" {","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L765-L801","documentation":"The workspace (.beads) is already initialized against a recorded Dolt database, and bd init was invoked with an explicit --database flag naming a different database. Since --database is the authoritative selector, bd refuses to silently re-point the workspace and asks you to drop or match the flag.","triggerScenarios":"`bd init --database new_name` in a directory where .beads already exists and existingWorkspaceDBName() returns a different name, and initIfMissingDatabaseMismatch flags the mismatch.","commonSituations":"Re-running init in a cloned repo with a leftover config but a different database name; renaming the project and wanting a new database name without wiping; scripted init with a templated name that drifted.","solutions":["Remove the --database flag so the existing workspace is reused","Or pass the same value already recorded: bd init --database <existing-name>","Delete/reinitialize the workspace intentionally if you truly want a fresh database"],"exampleFix":"// before\nbd init --database proj_v2   # workspace is proj_v1\n// after\nbd init                      # reuse existing, or:\nbd init --database proj_v1","handlingStrategy":"validation","validationCode":"existing=$(cat .beads/database.name 2>/dev/null); [ -n \"$existing\" ] && [ \"$existing\" != \"$DB\" ] && echo \"Refusing: workspace is $existing\" && unset DB","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In scripts, omit --database on re-init; bd reuses the existing workspace safely","Store the canonical database name in CI config once and reuse it","Check .beads contents before re-initializing a cloned repo"],"tags":["cli","workspace","idempotency","database-name"],"backgroundTag":"workspace-already-initialized","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}