部署在缓存刷新时失败:“在‘缓存’命名空间中未定义命令”错误
最近更新: 2025年5月5日
当在云基础架构上的Adobe Commerce中部署失败,出现 未在“cache”命名空间 错误中定义任何命令,请确定这些配置中剩余的无效行。 如果您只有一个网站,则对网站的第二个测试不适用,并且您只需要测试商店。
描述
环境
云基础架构上的Adobe Commerce 2.4.x
问题
警告:在执行这些步骤之前,请先在实时生产站点中备份数据库。
本文为部署失败并且日志中的错误之一类似以下时的问题提供了解决方案:
[ 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.
重现步骤:
尝试部署。
预期的结果:
您已成功部署。
实际结果:
您未成功部署。 在日志中,您看到一个部署错误,其消息类似于: 缓存命名空间 中没有命令。
原因
core_config_data
表包含数据库中不再存在的商店ID或网站ID的配置。 当您从其他实例/环境导入了数据库备份,并且这些作用域的配置保留在数据库中时,即使关联的存储/网站已被删除,也会发生这种情况。
解决方法
如果您只有一个网站,则对网站的第二个测试不适用,并且您只需要测试商店。
要解决此问题,请确定这些配置中剩余的无效行。
-
SSH到服务器并运行此命令:
bin/magento
-
该错误消息可能指示哪些行和表保留在已删除站点的数据库中。 例如,以下错误表示未找到所请求的存储:
... In StoreRepository.php line 112: The store that was requested wasn't found. Verify the store and try again.
-
运行此MySQL查询以验证是否找不到存储,如步骤2中的错误消息所示。
select distinct scope_id from core_config_data where scope='stores' and scope_id not in (select store_id from store);
-
运行以下MySQL语句以删除无效行:
delete from core_config_data where scope='stores' and scope_id not in (select store_id from store);
-
再次运行此命令:
bin/magento
如果收到如下错误,表示未找到所请求的ID为X的网站,则数据库中会保留已删除的网站和商店中的配置。
In WebsiteRepository.php line 110: The website with id X that was requested wasn't found. Verify the website and try again.
运行此MySQL查询并验证是否找不到该网站:
select distinct scope_id from core_config_data where scope='websites' and scope_id not in (select website_id from store_website);
-
运行此MySQL语句可从网站配置中删除无效行:
delete from core_config_data where scope='websites' and scope_id not in (select website_id from store_website);
相关阅读
recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f