{"record":{"id":"685bc0e62521acc1","repo":"octobercms/october","slug":"cannot-delete-the-active-theme-try-making-another","errorCode":null,"errorMessage":"Cannot delete the active theme, try making another theme active first.","messagePattern":"Cannot delete the active theme, try making another theme active first\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/ThemeManager.php","lineNumber":431,"sourceCode":"     */\n    public function purgeDatabaseTemplates(string $dirName)\n    {\n        Db::table('cms_theme_templates')->where('source', $dirName)->delete();\n    }\n\n    /**\n     * deleteTheme completely delete a theme from the system\n     */\n    public function deleteTheme(string $theme)\n    {\n        $theme = CmsTheme::load($theme);\n\n        if (!$theme->isValid()) {\n            return false;\n        }\n\n        if ($theme->isActiveTheme()) {\n            throw new ApplicationException(__('Cannot delete the active theme, try making another theme active first.'));\n        }\n\n        $theme->removeCustomData();\n\n        // Delete from file system\n        $themePath = $theme->getPath();\n        if (is_dir($themePath)) {\n            File::deleteDirectory($themePath);\n        }\n    }\n\n    /**\n     * findMissingDependencies scans the system plugins to locate any dependencies that\n     * are not currently installed. Returns an array of plugin codes that are needed.\n     *\n     *     ThemeManager::instance()->findMissingDependencies();\n     *\n     * @return array","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/ThemeManager.php#L413-L449","documentation":"ThemeManager::deleteTheme() refuses to delete the theme that is currently the active front-end theme, protecting the live site from losing its theme. The guard is $theme->isActiveTheme(); deleteTheme also silently returns false when the theme fails isValid(), so this exception is specifically about deleting the active one.","triggerScenarios":"Calling ThemeManager::instance()->deleteTheme('demo') while 'demo' is the active theme, or deleting the active theme from the backend theme-management UI.","commonSituations":"Removing the starter/demo theme after building a custom theme without switching the active theme first; cleanup scripts that iterate and delete every theme; duplicated environments where the active theme code points at the theme being removed.","solutions":["Activate another theme first: Theme::setActiveTheme('mysite') or switch it in the backend theme picker, then retry the delete","Guard your code: only call deleteTheme when !$theme->isActiveTheme()","If the active theme is itself broken, set 'activeTheme' in config/cms.php to a valid theme and retry"],"exampleFix":"// before\nCms\\Classes\\ThemeManager::instance()->deleteTheme('demo'); // 'demo' is active -> throws\n\n// after\nCms\\Classes\\Theme::setActiveTheme('mysite');\nCms\\Classes\\ThemeManager::instance()->deleteTheme('demo');","handlingStrategy":"validation","validationCode":"$theme = \\Cms\\Classes\\Theme::load($code);\nif ($theme && $theme->isValid() && !$theme->isActiveTheme()) {\n    \\Cms\\Classes\\ThemeManager::instance()->deleteTheme($code);\n}","typeGuard":null,"tryCatchPattern":"try { \\Cms\\Classes\\ThemeManager::instance()->deleteTheme($code); } catch (\\October\\Rain\\Exception\\ApplicationException $e) { // active theme: switch first, then retry }","preventionTips":["Always check $theme->isActiveTheme() before delete operations","Build cleanup scripts to switch the active theme to a known-good one before removing themes","Never delete themes blindly in automation; resolve the active code first"],"tags":["cms","theme","delete","backend","winter-cms"],"backgroundTag":"delete-active-resource","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}