{"record":{"id":"7e0c9b23362f3287","repo":"octobercms/october","slug":"unable-to-delete-site-group-because-it-is-being-us","errorCode":null,"errorMessage":"Unable to delete site group because it is being used by existing site definitions (:count).","messagePattern":"Unable to delete site group because it is being used by existing site definitions \\(:count\\)\\.","errorType":"validation","errorClass":"October\\Rain\\Exception\\ValidationException","httpStatus":null,"severity":"error","filePath":"modules/system/models/SiteGroup.php","lineNumber":67,"sourceCode":"    public static function syncDefaultGroup()\n    {\n        if (static::count() > 0) {\n            return;\n        }\n\n        static::create([\n            'name' => 'Default',\n            'code' => 'default',\n        ]);\n    }\n\n    /**\n     * beforeDelete\n     */\n    public function beforeDelete()\n    {\n        if (($count = $this->sites()->count()) > 0) {\n            throw new ValidationException(['name' => __(\"Unable to delete site group because it is being used by existing site definitions (:count).\", ['count' => $count])]);\n        }\n    }\n\n    /**\n     * afterDelete\n     */\n    public function afterDelete()\n    {\n        PluginSiteGroup::where('site_group_id', $this->id)->delete();\n\n        Site::resetCache();\n    }\n\n    /**\n     * afterSave\n     */\n    public function afterSave()\n    {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/system/models/SiteGroup.php#L49-L85","documentation":"Model event guard in SiteGroup::beforeDelete: the group still has associated site definitions, so deleting it would orphan those sites. The user must reassign or delete the :count sites in the group before removing the group.","triggerScenarios":"Thrown at modules/system/models/SiteGroup.php:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move or delete the site definitions assigned to the group first","Reassign the sites to another group before deleting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","contentChangedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}