clockworklabs/SpacetimeDB · error · anyhow::Error

No database target matches '{}'. Available databases: {}

Error message

No database target matches '{}'. Available databases: {}

What it means

`spacetime publish <db>` matches the CLI database name against spacetime.json targets. If nothing matches and the config holds more than one target, publish bails and lists the available database names. Special case: with exactly one target, publish instead merges the CLI name onto that target (which is why init's random-suffix names still work) (publish.rs:155).

Source

Thrown at crates/cli/src/subcommands/publish.rs:155

                    .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_targets

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Publish using one of the database names printed in the error message, exactly as shown
  2. Edit spacetime.json so one target's database field equals the name you want to pass
  3. Remove extra targets so the single-target merge path applies
  4. Bypass the config entirely with --no-config

Example fix

// before
spacetime publish mydb
// after: use a listed name, or align the config
spacetime publish mydb_dev
// spacetime.json: { "database": "mydb" }
Defensive patterns

Strategy: validation

Validate before calling

db="mydb"
jq -e --arg d "$db" '[.. | objects | select(.database? == $d)] | length > 0' spacetime.json \
  || { echo "database '$db' not defined in spacetime.json" >&2; exit 2; }
spacetime publish "$db"

Prevention

When it happens

Trigger: `spacetime publish somedb` where spacetime.json declares 2+ targets and none has database == "somedb".

Common situations: `spacetime init` generated a database name with a random suffix that differs from the name you pass on the CLI; typos; spacetime.json listing several environments (dev/staging/prod); renamed databases.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/9c6b457c44ca5d9e. Report an issue: GitHub.