I’d like to add before we begin, which trips many people up, because once you create the theme directory structure and load Magento Admin, the directory structure, becomes the theme name, and an entry is created in the database.
If then, the directory structure is deleted, there are still references to it in the database, which can cause issues if not taken care of properly. So I would like to go over the very first thing you should know when naming your theme, unlike Magento 1,
the Vendor Namespace will be capitalized but the theme name will be all lower case! Example
app/design/frontend/Magefoo/footheme/. This is important, many people capitalize both the Vendor Namespace and the theme name, which then causes issue down the road, they realize there mistake, and delete the directory structure, but then the theme still exists in admin!
Arrgghh….If you are that guy, here is how to delete the theme reference in the Magento 2 database as well.
note, to delete a theme properly, you should use the
bin/magento theme:uninstall command, and follow the directions here
However, for emergency situations, like if you already deleted the directory structure, then do this:
- Delete the content from app/design/frontend/
- Delete the
SELECT * FROM theme;(find entry for your theme)
DELETE FROM theme WHERE theme_id = '<theme_number>';
SELECT * FROM core_config_data WHERE path like '%theme%';(replace your default theme id in any place the records have your old theme id).
- If production mode, deploy static content
bin/magento setup:static-content:deploy& recompile
- Flush cache
If the theme has a configuration in Magento Admin, then it is important to delete all references to the theme in table
eav_attribute this table associates any Backend Models with the themes configuration and if the theme has its own Backend Models then the store will error if these are not removed.
this is not an exhaustive list as there still may be illegitimate theme references in other database tables as well, these are only the one’s I know about.