{"record":{"id":"eff81f1afb9423bd","repo":"mastra-ai/mastra","slug":"project-project-name-has-no-environments-creat","errorCode":null,"errorMessage":"Project ${project.name} has no environments. Create one with: mastra env create <name>","messagePattern":"Project (.+?) has no environments\\. Create one with: mastra env create <name>","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/db/db.ts","lineNumber":355,"sourceCode":"\n/**\n * When the user runs `mastra env db create` without an environment argument\n * and without --shared, pick the environment to scope the new database to:\n *  - exactly one environment → use it\n *  - multiple environments + interactive TTY → prompt with a picker\n *  - multiple environments + non-interactive → fail with a clear message\n *  - zero environments → fail (nothing to attach to)\n */\nexport 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({","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/db/db.ts#L337-L373","documentation":"resolveDefaultEnvironment() is used when no environment argument is given (e.g. `mastra env db create` without <env> or --shared); if the project has zero environments there is no default to resolve, so it throws with instructions to create one first.","triggerScenarios":"Running a db command that needs an implicit environment on a freshly created project that has never had `mastra env create` run.","commonSituations":"New Mastra Cloud project onboarding, automation that skipped environment provisioning, or operating against the wrong project which happens to have no environments.","solutions":["Create an environment: `mastra env create <name>` (e.g. production), then re-run the db command.","Verify you're targeting the intended project with `--project <name>`.","Use `mastra env list` to confirm the environment was created before retrying."],"exampleFix":"// before\nmastra env db create --kind turso   # project has no environments\n// after\nmastra env create production\nmastra env db create production --kind turso","handlingStrategy":"validation","validationCode":"const envs = await listEnvironments();\nif (envs.length === 0) {\n  throw new Error('Create an environment first: mastra env create <name>');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dbCreate();\n} catch (e) {\n  if (/has no environments/.test((e as Error).message)) {\n    console.error('Provision an environment with `mastra env create <name>` before creating databases.');\n  }\n}","preventionTips":["Provision at least one environment as part of project onboarding.","In automation, check `mastra env list` is non-empty before db commands.","Confirm --project points at the intended, provisioned project."],"tags":["cli","environment","prerequisite","cloud"],"backgroundTag":"missing-prerequisite-resource","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}