{"record":{"id":"9c6b457c44ca5d9e","repo":"clockworklabs/SpacetimeDB","slug":"no-database-target-matches-available-databas","errorCode":null,"errorMessage":"No database target matches '{}'. Available databases: {}","messagePattern":"No database target matches '(.+?)'\\. Available databases: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/publish.rs","lineNumber":163,"sourceCode":"                    .get(\"database\")\n                    .and_then(|v| v.as_str())\n                    .is_some_and(|db| pattern.matches(db))\n            })\n            .collect();\n\n        if matched.is_empty() {\n            // When there is exactly one target in the config and the CLI-provided\n            // database name doesn't match it, use that target's settings (e.g.\n            // native-aot, module-path, build-options) and let CommandConfig merge\n            // the CLI database name on top.  This handles the common case where\n            // `spacetime init` generated a random database suffix that differs\n            // from the name the user passes on the CLI, while still picking up\n            // module-specific config.\n            let all_targets = spacetime_config.collect_all_targets_with_inheritance();\n            if all_targets.len() == 1 {\n                all_targets\n            } else {\n                anyhow::bail!(\n                    \"No database target matches '{}'. Available databases: {}\",\n                    cli_database,\n                    all_targets\n                        .iter()\n                        .filter_map(|t| t.fields.get(\"database\").and_then(|v| v.as_str()))\n                        .collect::<Vec<_>>()\n                        .join(\", \")\n                );\n            }\n        } else {\n            matched\n        }\n    } else {\n        all_targets\n    };\n\n    // Build CommandConfig for each target\n    let configs: Vec<CommandConfig> = filtered_targets","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/eddf9f5014579a50d4b67630e28b6e15cad9c4af/crates/cli/src/subcommands/publish.rs#L145-L181","documentation":"When a spacetime.json is loaded and you pass a database name on the CLI, the name is treated as a glob pattern matched against the `database` field of every configured target. With two or more targets and zero matches, publish aborts and lists the available database names. (With exactly one target there is a fallback: its settings are reused and the CLI name overrides the database.)","triggerScenarios":"`spacetime publish foo` where spacetime.json defines targets `mydb-dev` and `mydb-prod`; typos in the name; unquoted shell glob characters (`*`, `?`, `[`) in the database name altering the match; renaming the database in spacetime.json but not in scripts.","commonSituations":"Multi-environment configs (dev/staging/prod targets); `spacetime init` generating a random-suffixed name while scripts hardcode the plain name; names containing glob metacharacters.","solutions":["Publish using one of the names printed in the error's Available databases list","Add or fix the target's `database` field in spacetime.json so the CLI name matches","Quote the argument in your shell so glob metacharacters reach the CLI intact, or escape them intentionally","Temporarily bypass config selection with --no-config if you want pure CLI-args publishing"],"exampleFix":"# before\nspacetime publish mydb\n# error: No database target matches 'mydb'. Available databases: mydb-3f9k, other\n# after\nspacetime publish \"mydb-3f9k\"","handlingStrategy":"validation","validationCode":"# derive the database list from config and assert your name matches one\njq -r '.targets[].database // empty' spacetime.json | grep -qx \"$DB\" || { echo \"no target for $DB\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match publish(db).await {\n    Err(e) if e.to_string().starts_with(\"No database target matches\") => {\n        // parse the 'Available databases:' suffix and surface a picker\n    }\n    rest => rest,\n}","preventionTips":["Keep spacetime.json database names and CI variables in one source of truth","Quote database arguments in shells to keep glob metacharacters literal","Remember the single-target fallback: with one target, any CLI name still works"],"tags":["spacetime-publish","spacetime-json","glob","config","cli"],"backgroundTag":"config-target-not-found","analyzedSha":"eddf9f5014579a50d4b67630e28b6e15cad9c4af","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}