{"record":{"id":"9c6b457c44ca5d9e","repo":"clockworklabs/SpacetimeDB","slug":"no-database-target-matches-available-databas-9c6b45","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":155,"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":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/publish.rs#L137-L173","documentation":"`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).","triggerScenarios":"`spacetime publish somedb` where spacetime.json declares 2+ targets and none has database == \"somedb\".","commonSituations":"`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.","solutions":["Publish using one of the database names printed in the error message, exactly as shown","Edit spacetime.json so one target's database field equals the name you want to pass","Remove extra targets so the single-target merge path applies","Bypass the config entirely with --no-config"],"exampleFix":"// before\nspacetime publish mydb\n// after: use a listed name, or align the config\nspacetime publish mydb_dev\n// spacetime.json: { \"database\": \"mydb\" }","handlingStrategy":"validation","validationCode":"db=\"mydb\"\njq -e --arg d \"$db\" '[.. | objects | select(.database? == $d)] | length > 0' spacetime.json \\\n  || { echo \"database '$db' not defined in spacetime.json\" >&2; exit 2; }\nspacetime publish \"$db\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use database names exactly as defined in spacetime.json","Keep one target per spacetime.json to benefit from the single-target merge rule","Diff the CLI name against the config before scripted publishes"],"tags":["publish","spacetime-json","config","database-name"],"backgroundTag":"config-target-not-found","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}