{"record":{"id":"431fa05749e5d9da","repo":"bytebase/bytebase","slug":"instance-target-q-does-not-belong-to-project-q","errorCode":null,"errorMessage":"instance target %q does not belong to project %q","messagePattern":"instance target %q does not belong to project %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/component/review/evaluator.go","lineNumber":520,"sourceCode":"\t\t\t\treturn err\n\t\t\t}\n\t\t\ttargets = append(targets, specTarget{\n\t\t\t\tdatabase:    db,\n\t\t\t\tsheetSha256: sheetSha256,\n\t\t\t})\n\t\t}\n\t\treturn nil\n\t}\n\n\tfor _, spec := range specs {\n\t\tswitch config := spec.Config.(type) {\n\t\tcase *storepb.PlanConfig_Spec_CreateDatabaseConfig:\n\t\t\ttargetProjectID, instanceID, err := common.GetInstanceResourceName(config.CreateDatabaseConfig.Target)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, errors.Wrapf(err, \"failed to parse instance from target %q\", config.CreateDatabaseConfig.Target)\n\t\t\t}\n\t\t\tif targetProjectID != nil && *targetProjectID != projectID {\n\t\t\t\treturn nil, errors.Errorf(\"instance target %q does not belong to project %q\", config.CreateDatabaseConfig.Target, projectID)\n\t\t\t}\n\t\t\tif err := validateInstanceTarget(ctx, stores, targetProjectID, instanceID); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\t// For CREATE_DATABASE, create a synthetic database message\n\t\t\t// since the database doesn't exist yet\n\t\t\ttargets = append(targets, specTarget{\n\t\t\t\tdatabase: &store.DatabaseMessage{\n\t\t\t\t\tInstanceID:             instanceID,\n\t\t\t\t\tDatabaseName:           config.CreateDatabaseConfig.Database,\n\t\t\t\t\tEffectiveEnvironmentID: new(config.CreateDatabaseConfig.Environment),\n\t\t\t\t},\n\t\t\t\tsheetSha256: \"\",\n\t\t\t})\n\n\t\tcase *storepb.PlanConfig_Spec_ChangeDatabaseConfig:\n\t\t\tif err := appendTargets(config.ChangeDatabaseConfig.Targets, config.ChangeDatabaseConfig.SheetSha256); err != nil {\n\t\t\t\treturn nil, err","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/component/review/evaluator.go#L502-L538","documentation":"After parsing the instance resource name from a CreateDatabaseConfig target, unfoldSpecTargets checks that the instance's project component matches the project the plan belongs to. This error means the create-database target points at an instance owned by a different project — cross-project targeting is not allowed when creating databases through a plan.","triggerScenarios":"A plan in project A has a spec whose CreateDatabaseConfig.Target is \"projects/B/instances/x\"; the targetProjectID parsed from the target differs from the plan's projectID.","commonSituations":"Plans copied between projects; UI retaining a stale target after the plan was moved; manual plan imports across projects; tenant projects referencing shared instances.","solutions":["Change the spec target to an instance resource name under the same project as the plan (\"projects/<plan-project>/instances/<i>\")","If the instance genuinely lives in another project, move the instance into this project or create the plan in that project instead","Regenerate the plan from the UI/API instead of editing targets by hand"],"exampleFix":"// before (plan in project \"app\")\n\"target\": \"projects/infra/instances/prod\"\n// after\n\"target\": \"projects/app/instances/prod\"","handlingStrategy":"validation","validationCode":"targetProject, targetInstance, err := common.GetInstanceResourceName(target)\nif err == nil && targetProject != nil && *targetProject != plan.ProjectID {\n\treturn fmt.Errorf(\"instance %q belongs to project %s, not %s\", target, *targetProject, plan.ProjectID)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only offer same-project instances in the create-database target picker","Re-validate targets when copying plans across projects","Avoid manual edits of cross-project targets in plan configs"],"tags":["create-database","cross-project","plan-config"],"backgroundTag":"invalid-argument-value","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}