{"record":{"id":"6d49f887fbfdb27d","repo":"bytebase/bytebase","slug":"plan-contains-both-database-group-and-databases-b","errorCode":null,"errorMessage":"plan contains both database group and databases, but only one is allowed","messagePattern":"plan contains both database group and databases, but only one is allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/api/v1/plan_service.go","lineNumber":678,"sourceCode":"\t}\n\t// Allow at most one ChangeDatabaseConfig with release.\n\tif releaseCount > 1 {\n\t\treturn nil, errors.Errorf(\"plan contains multiple change database configs with release, but only one is allowed\")\n\t}\n\n\t// Allow at most one instance.\n\tif len(instanceTargets) > 1 {\n\t\treturn nil, errors.Errorf(\"plan contains targets on multiple instances, but only one instance is allowed\")\n\t}\n\n\t// Allow at most one database group.\n\tif len(databaseGroups) > 1 {\n\t\treturn nil, errors.Errorf(\"plan contains multiple database groups, but only one is allowed\")\n\t}\n\n\t// Don't allow mixing database group and databases.\n\tif len(databaseGroups) > 0 && len(databaseNames) > 0 {\n\t\treturn nil, errors.Errorf(\"plan contains both database group and databases, but only one is allowed\")\n\t}\n\n\t// Validate resources existence.\n\tif len(instanceTargets) == 1 {\n\t\tinstance, err := getInstanceMessage(ctx, s, instanceTargets[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif instance.Deleted {\n\t\t\treturn nil, connect.NewError(connect.CodeNotFound, errors.Errorf(\"instance %q has been deleted\", instanceTargets[0]))\n\t\t}\n\t}\n\n\tif len(databaseGroups) == 1 {\n\t\tname := databaseGroups[0]\n\t\tgroupProjectID, _, err := common.GetProjectIDDatabaseGroupID(name)\n\t\tif err != nil {\n\t\t\treturn nil, connect.NewError(connect.CodeInvalidArgument, errors.Errorf(\"invalid database group name %q\", name))","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/api/v1/plan_service.go#L660-L696","documentation":"A plan spec must select its target databases via exactly one mechanism: a database group, or an explicit list of databases. validateSpecs rejects CreatePlan/UpdatePlan requests that set both a database group resource and explicit database resources in the same plan, because the combined targeting semantics would be ambiguous.","triggerScenarios":"Calling CreatePlan or UpdatePlan where plan specs contain both a database_group resource name and database resource names (e.g. projects/{p}/databases/{db}) simultaneously — typically when a client appends a fallback database entry alongside a group, or merges two different spec styles.","commonSituations":"UI or tooling that pre-fills explicit databases and then adds a group when the user changes selection mode without clearing the other field; migration of older plan payloads that mixed both styles; hand-written API scripts constructing specs incorrectly.","solutions":["Remove the explicit database resources and keep only the database group spec","Remove the database group spec and keep only the explicit database list","If both targets are needed, issue separate plans — one per targeting style"],"exampleFix":"// before\nplan.specs = [{databaseGroup: \"projects/p/databaseGroups/prod\"},\n              {databases: [\"projects/p/databases/db1\"]}]\n// after\nplan.specs = [{databaseGroup: \"projects/p/databaseGroups/prod\"}]","handlingStrategy":"validation","validationCode":"if len(spec.GetDatabaseGroup()) > 0 && len(spec.GetDatabases()) > 0 {\n  return fmt.Errorf(\"spec sets both databaseGroup and databases; pick one\")\n}","typeGuard":null,"tryCatchPattern":"var cerr *connect.Error\nif errors.As(err, &cerr) && strings.Contains(cerr.Message(), \"both database group and databases\") {\n  // clear one targeting style and resubmit\n}","preventionTips":["Model targeting mode as an enum in client code so only one field can be set","Clear the databases list whenever a group is selected (and vice versa) in UI code"],"tags":["plan","validation","database-group","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","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"}