Deployment failed on cache flush: “There are no commands defined in the ‘cache’ namespace” error
When deployment fails in Adobe Commerce on cloud infrastructure with a There are no commands defined in the “cache” namespace error, or when any bin/magento CLI command fails with an error such as Invalid entity_type specified: customer, it usually indicates invalid or missing configuration data in the database (for example, orphaned store/website rows or incomplete eav_entity_type definitions).
Use the tests in this article to identify and correct those invalid rows; if you have only one website, the second test for websites does not apply and you only need to run the tests for stores and the eav_entity_type table.
Description description
Environment
Adobe Commerce on cloud infrastructure 2.4.x
Issue
This article provides a solution for the issue when your deployment fails and one of the errors in the log looks like this:
[ YEAR-DAYTIME] ERROR: [ 127] The command "php ./bin/magento cache:flush --ansi --no-interaction" failed.
There are no commands defined in the "cache" namespace.
...
W: There are no commands defined in the "cache" namespace.
Steps to reproduce:
Attempt to deploy.
Expected results:
You deploy successfully.
Actual results:
You don’t deploy successfully. In the logs you see a deployment error with a message similar to: There are no commands in the cache namespace.
Cause
There are two known causes for this issue:
- Deleted stores or websites with orphaned configuration data. The
core_config_datatable contains configurations for a store ID or website ID that no longer exists in the database. This typically occurs when you have imported a database backup from another instance or environment, and the configurations for those scopes remain in the database even though the associated store(s) or website(s) have been deleted. - Empty or incomplete
eav_entity_typetable. Theeav_entity_typetable is empty or is missing one or more requiredentity_typedefinitions. When you run anybin/magentoCLI command, you see an error similar to the following.
In Config.php line 472:
Invalid entity_type specified: customer
This indicates that the customer entity type definition is missing from the eav_entity_type table (or the table is completely empty). This situation also commonly arises after importing a database backup from another instance or environment where the eav_entity_type table was not exported or restored correctly.
Resolution resolution
Warning: Back up the database first if you’re doing this on a live Production site before performing any of the following steps.
Use the appropriate solution below depending on which cause applies to your environment.
Solution for Cause 1: Orphaned configurations for deleted
stores/websites
Note: If you have only one website, the website-level checks do not apply, and you only need to test for stores.
To solve this issue, identify and remove the invalid rows left from configurations for stores or websites that no longer exist.
- SSH into the Adobe Commerce on cloud infrastructure environment and run the
following command to surface store or website configuration errors.
bin/magento
- Check for a missing store error, as the error message might indicate which
rows and tables remain in the database from deleted sites.
*In StoreRepository.php line 112:
The store that was requested wasn’t found. Verify the store and try again.
*
- Run the following MySQL query to find configuration rows pointing to
non-existent stores.
SELECT DISTINCT scope_id
FROM core_config_data
WHERE scope = 'stores'
AND scope_id NOT IN (SELECT store_id FROM store);
- Note:
Run SELECT queries first, validate results in a non-Production environment,
and follow your change-management process before running any DELETE
statements.
After verifying the results, delete the orphaned store configuration rows.
DELETE FROM core_config_data
WHERE scope = 'stores'
AND scope_id NOT IN (SELECT store_id FROM store);
- Re-run
bin/magentoand check for missing website errors.
bin/magento
If you get an error indicating that the requested website with ID X was not found, it means there are orphaned website-level configurations as well.
*In WebsiteRepository.php line 110:
The website with id X that was requested wasn’t found. Verify the website and
try again.
*
Run the following MySQL query to find configurations for websites that no longer exist.
SELECT DISTINCT scope_id
FROM core_config_data
WHERE scope = 'websites'
AND scope_id NOT IN (SELECT website_id FROM store_website);
Note: Run SELECT queries first, validate results in a non-Production environment, and follow your change-management process before running any DELETE statements.
Remove the orphaned website configuration rows.
DELETE FROM core_config_data
WHERE scope = 'websites'
AND scope_id NOT IN (SELECT website_id FROM store_website);
After cleaning up these rows, run your deployment again. The cache-related CLI commands should now be recognized, and deployment should proceed successfully.
Solution for Cause 2: Empty or missing entries in theeav_entity_type table
The Commerce database table eav_entity_type is empty or missing one or more required entity_type rows (for example, customer). This typically happens after importing a database backup from another instance or environment where the eav_entity_type table was not exported or restored correctly.
- To validate the error and table contents, SSH to the Commerce server or Cloud
container.
Run the following command.
bin/magento
Confirm that the error is as follows.
*In Config.php line 472:
Invalid entity_type specified: customer
*
Connect to the MySQL database used by your Adobe Commerce on cloud infrastructure environment and inspect the eav_entity_type table.
SELECT entity_type_id, entity_type_code
FROM eav_entity_type
ORDER BY entity_type_id;
If this query returns no rows, the table is empty.
If there is no row with entity_type_code = 'customer' (or the entity type shown in the error), that entity type is missing.
- If the table is empty or missing the entity type mentioned in the error,
restore or import theeav_entity_typetable from a known good
backup taken from the same Commerce instance and version.
Follow your MySQL backup and restore procedures or consult your DBA to ensure that the following conditions are met.
- The table structure matches the current Commerce version.
- All required entity types (for example,
customer,catalog_product) are present.
- After restoring, run the following commands to verify that the
Invalid entity_type specified error no longer appears.
bin/magento setup:upgrade
bin/magento cache:flush
If these commands complete successfully, attempt the deployment again.