clockworklabs/SpacetimeDB · error · anyhow::Error
No database target matches
Error message
No database target matches '{}'. Available databases: {} What it means
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.)
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
Example fix
# before spacetime publish mydb # error: No database target matches 'mydb'. Available databases: mydb-3f9k, other # after spacetime publish "mydb-3f9k"
Defensive patterns
Strategy: validation
Validate before calling
# derive the database list from config and assert your name matches one
jq -r '.targets[].database // empty' spacetime.json | grep -qx "$DB" || { echo "no target for $DB"; exit 1; } Try / catch
match publish(db).await {
Err(e) if e.to_string().starts_with("No database target matches") => {
// parse the 'Available databases:' suffix and surface a picker
}
rest => rest,
} Prevention
- 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
When it happens
Trigger: `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.
Common situations: Multi-environment configs (dev/staging/prod targets); `spacetime init` generating a random-suffixed name while scripts hardcode the plain name; names containing glob metacharacters.
Related errors
- No matching target found in spacetime.json for the provided…
- database is a required field in publish config
- Aborted.
- Aborting because major version upgrade was not accepted.
- Cannot use generate-entry-specific arguments
AI-assisted analysis of clockworklabs/SpacetimeDB@eddf9f5014 (2026-08-20).
Data as JSON: /api/errors/9c6b457c44ca5d9e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/subcommands/publish.rs:163
.get("database")
.and_then(|v| v.as_str())
.is_some_and(|db| pattern.matches(db))
})
.collect();
if matched.is_empty() {
// When there is exactly one target in the config and the CLI-provided
// database name doesn't match it, use that target's settings (e.g.
// native-aot, module-path, build-options) and let CommandConfig merge
// the CLI database name on top. This handles the common case where
// `spacetime init` generated a random database suffix that differs
// from the name the user passes on the CLI, while still picking up
// module-specific config.
let all_targets = spacetime_config.collect_all_targets_with_inheritance();
if all_targets.len() == 1 {
all_targets
} else {
anyhow::bail!(
"No database target matches '{}'. Available databases: {}",
cli_database,
all_targets
.iter()
.filter_map(|t| t.fields.get("database").and_then(|v| v.as_str()))
.collect::<Vec<_>>()
.join(", ")
);
}
} else {
matched
}
} else {
all_targets
};
// Build CommandConfig for each target
let configs: Vec<CommandConfig> = filtered_targetsView on GitHub (pinned to eddf9f5014)