{"record":{"id":"38ee52647ddb0c6e","repo":"clockworklabs/SpacetimeDB","slug":"database-is-not-in-the-config-file-if-you-wa","errorCode":null,"errorMessage":"Database '{}' is not in the config file. If you want to run against a database outside of the current project, pass --no-config.","messagePattern":"Database '(.+?)' is not in the config file\\. If you want to run against a database outside of the current project, pass --no-config\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/db_arg_resolution.rs","lineNumber":55,"sourceCode":"#[derive(Debug, Clone, PartialEq, Eq)]\npub(crate) struct ResolvedDbArgs {\n    pub database: String,\n    pub server: Option<String>,\n    pub remaining_args: Vec<String>,\n}\n\n/// Build an error for when the first positional arg doesn't match any configured database target.\nfn unknown_database_error(db: &str, config_targets: &[ConfigDbTarget]) -> anyhow::Error {\n    let known: Vec<&str> = config_targets.iter().map(|t| t.database.as_str()).collect();\n    if known.len() > 1 {\n        anyhow::anyhow!(\n            \"Multiple databases found in config: {}. Please specify which database to use, \\\n             or pass --no-config to use '{}' directly.\",\n            known.join(\", \"),\n            db\n        )\n    } else {\n        anyhow::anyhow!(\n            \"Database '{}' is not in the config file. \\\n             If you want to run against a database outside of the current project, pass --no-config.\",\n            db\n        )\n    }\n}\n\npub(crate) fn load_config_db_targets(no_config: bool) -> anyhow::Result<Option<Vec<ConfigDbTarget>>> {\n    if no_config {\n        return Ok(None);\n    }\n\n    Ok(find_and_load_with_env(None)?\n        .map(|loaded| {\n            loaded\n                .config\n                .collect_all_targets_with_inheritance()\n                .iter()","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/crates/cli/src/subcommands/db_arg_resolution.rs#L37-L73","documentation":"The single-target variant of unknown_database_error (crates/cli/src/subcommands/db_arg_resolution.rs:51): the project's spacetime.json defines exactly one database target, and the first positional argument of an ambiguous-arg command (call/subscribe/describe) does not equal that configured name. Because these commands cannot tell a database name from their own first argument, there is no auto-fallthrough and the mismatch is rejected with a pointer to --no-config.","triggerScenarios":"Running `spacetime call myfn 1` where the single configured target's database is `foo` - 'myfn' is not 'foo', so the resolver refuses to guess whether myfn is a database or a reducer name; renaming the database in spacetime.json but keeping old scripts; copy-pasting a command between projects.","commonSituations":"Renamed or re-published databases under new names while scripts still pass the old one; multiple projects with different db names sharing scripts; onboarding examples run in a configured project directory.","solutions":["Use the configured database's exact name (shown in the error) as the first positional argument.","Run without positional ambiguity by relying on the single target: `spacetime call <function_name> <args>` - the database is implied.","Pass --no-config to treat the first argument as an ad-hoc database outside the project: `spacetime call <db> <fn> <args> --no-config`."],"exampleFix":"# before: 'myfn' != configured database 'foo'\nspacetime call myfn 1\n# after: rely on the single configured target\nspacetime call myfn 1            # db resolved from config\n# or bypass config\nspacetime call other-db myfn 1 --no-config","handlingStrategy":"validation","validationCode":"# Single-target project: either omit the db (config implies it) or match the configured name.\nconfigdb=$(jq -r '.databases | to_entries[0].value.database' spacetime.json 2>/dev/null)\n[ -z \"$configdb\" ] || [ \"$1\" = \"$configdb\" ] || [ $# -eq 0 ] || { echo \"use '$configdb' or pass --no-config\" >&2; exit 2; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After renaming a database, update every script that names it, or drop the name and let the single config target imply it.","Run commands from the project root so the intended spacetime.json is the one discovered.","Use --no-config consciously for out-of-project databases instead of hoping a mismatched name falls through."],"tags":["spacetimedb","cli","config","database-targets","name-mismatch"],"backgroundTag":"database-not-in-config","analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}