clockworklabs/SpacetimeDB · error · anyhow::Error
No database target matches '{}'. Available databases: {}
Error message
No database target matches '{}'. Available databases: {} What it means
`spacetime generate --database <selector>` picks the generate targets to run by matching each spacetime.json target's `database` field against a glob pattern. When the pattern matches no target, the CLI aborts and prints every database name it found across all inheritance-merged targets. The glob matcher is the `glob` crate, so `*` and `?` are active characters in the selector.
Source
Thrown at crates/cli/src/subcommands/generate.rs:100
// Filter by database name pattern (glob) if provided via CLI
let filtered_targets = if let Some(cli_database) = args.get_one::<String>("database") {
let pattern =
glob::Pattern::new(cli_database).with_context(|| format!("Invalid glob pattern: {cli_database}"))?;
let matched: Vec<_> = all_targets
.into_iter()
.filter(|target| {
target
.fields
.get("database")
.and_then(|v| v.as_str())
.is_some_and(|db| pattern.matches(db))
})
.collect();
if matched.is_empty() {
anyhow::bail!(
"No database target matches '{}'. Available databases: {}",
cli_database,
spacetime_config
.collect_all_targets_with_inheritance()
.iter()
.filter_map(|t| t.fields.get("database").and_then(|v| v.as_str()))
.collect::<Vec<_>>()
.join(", ")
);
}
matched
} else {
all_targets
};
// Collect generate entries from matched targets, inheriting entity fields
// Deduplicate by (module_path, serialized_generate_entry)View on GitHub (pinned to 524b4487d9)
Solutions
- Compare your selector against the 'Available databases: ...' list printed in the error and re-run with an exact name from that list
- Add or fix the `database` field on the intended generate target(s) in spacetime.json
- Drop `--database` entirely to generate every target
- If the available list is empty, your spacetime.json targets lack `database` fields — define them or migrate the config to the database-centric target format
Example fix
// spacetime.json — before
{
"generate": { "targets": [ { "lang": "typescript", "out-dir": "src/generated" } ] }
}
// spacetime.json — after
{
"generate": { "targets": [ { "database": "mydb", "lang": "typescript", "out-dir": "src/generated" } ] }
}
// then: spacetime generate --database mydb Defensive patterns
Strategy: validation
Validate before calling
# Before `spacetime generate --database mydb`, confirm a target declares it: jq -e '.generate.targets[]? | select((.database // "") == "mydb")' spacetime.json > /dev/null \ || echo "WARN: no generate target with database=mydb in spacetime.json"
Try / catch
#!/usr/bin/env bash
if ! spacetime generate --database "$DB" 2>err.log; then
if grep -q "No database target matches" err.log; then
echo "Config drift: '$DB' not declared in spacetime.json (check 'Available databases' in err.log)" >&2
exit 2 # distinct exit code for config errors
fi
cat err.log >&2
exit 1
fi Prevention
- Declare an explicit `database` field on every generate target in spacetime.json
- Treat the error's 'Available databases' list as the source of truth before scripting around --database
- Remember --database is a glob: quote selectors containing * or ? so the shell doesn't expand them
- Validate spacetime.json against the expected target set in CI before invoking generate
When it happens
Trigger: Running `spacetime generate --database mydb` when no target in spacetime.json (or an inherited parent config) declares `"database": "mydb"`; a glob like `--database 'prod-*'` that matches nothing; targets that omit the `database` field entirely so the available list comes back empty.
Common situations: Typos or renamed databases in spacetime.json; monorepos where targets live in a parent config; configs written before per-target `database` fields existed; scripts that hardcode a database name from another environment.
Related errors
- transaction retry failed again
- wrong number of elements
- too many elements
- Manual database migrations are not yet implemented
- Multiple databases found in config: {}. Please specify which
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/2c6aa6a3b32feb2e.
Report an issue: GitHub.