{"record":{"id":"ba97539f48c3e0d9","repo":"mastra-ai/mastra","slug":"project-project-name-has-multiple-environments","errorCode":null,"errorMessage":"Project ${project.name} has multiple environments (${slugs}). Pass an environment name (e.g. `mastra env db create <env> --kind ...`) or use --shared to attach a project-scoped database.","messagePattern":"Project (.+?) has multiple environments \\((.+?)\\)\\. Pass an environment name \\(e\\.g\\. `mastra env db create <env> --kind \\.\\.\\.`\\) or use --shared to attach a project-scoped database\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/db/db.ts","lineNumber":364,"sourceCode":"export async function resolveDefaultEnvironment(\n  token: string,\n  orgId: string,\n  project: Project,\n  opts: { json?: boolean } = {},\n): Promise<Environment> {\n  const environments = await fetchEnvironments(token, orgId, project.id);\n\n  if (environments.length === 0) {\n    throw new Error(`Project ${project.name} has no environments. Create one with: mastra env create <name>`);\n  }\n\n  if (environments.length === 1) {\n    return environments[0]!;\n  }\n\n  if (opts.json || !isInteractive()) {\n    const slugs = environments.map(e => e.slug).join(', ');\n    throw new Error(\n      `Project ${project.name} has multiple environments (${slugs}). Pass an environment name (e.g. ` +\n        `\\`mastra env db create <env> --kind ...\\`) or use --shared to attach a project-scoped database.`,\n    );\n  }\n\n  // Prefer production as the pre-selected option when it exists.\n  const preferred = environments.find(e => e.type === 'production') ?? environments[0]!;\n\n  const selected = await p.select({\n    message: 'Which environment should this database be scoped to?',\n    initialValue: preferred.id,\n    options: environments.map(e => ({\n      value: e.id,\n      label: `${e.slug} (${e.type})`,\n      hint: e.region ?? undefined,\n    })),\n  });\n","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/db/db.ts#L346-L382","documentation":"When a project has multiple environments, resolveDefaultEnvironment() cannot pick a default safely in non-interactive mode (or with --json), so it throws listing all environment slugs and asking the caller to pass an environment name or use --shared. Interactive sessions instead prompt with production pre-selected.","triggerScenarios":"Running `mastra env db create --kind ...` (no env arg, no --shared) with --json set or in CI/non-TTY where isInteractive() is false, against a project with 2+ environments.","commonSituations":"CI pipelines and scripted deployments (non-interactive by nature), or --json output mode where prompting is impossible.","solutions":["Pass the target environment explicitly: `mastra env db create <env> --kind ...`.","Use `--shared` to create a project-scoped database when no environment binding is wanted.","Run the command interactively once to see a picker, then encode the chosen environment in your script."],"exampleFix":"// before\nmastra env db create --kind turso   # CI, multiple environments\n// after\nmastra env db create production --kind turso","handlingStrategy":"validation","validationCode":"const envs = await listEnvironments();\nif (envs.length > 1 && !explicitEnv && !shared) {\n  throw new Error(`Multiple environments (${envs.map(e => e.slug).join(', ')}): pass one explicitly or use --shared.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dbCreate();\n} catch (e) {\n  if (/has multiple environments/.test((e as Error).message)) {\n    const slugs = (e as Error).message.match(/\\(([^)]+)\\)/)?.[1] ?? '';\n    console.error(`Re-run with an explicit env, e.g. the first of: ${slugs}`);\n  }\n}","preventionTips":["Always pass an explicit environment in CI/non-interactive scripts.","Use --shared when the database should be project-scoped regardless of environments.","Parse the slug list from the error message to select a valid environment programmatically."],"tags":["cli","ambiguity","non-interactive","environment"],"backgroundTag":"ambiguous-target-requires-explicit-argument","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}