快取排清時部署失敗:「在'cache'名稱空間中未定義命令」錯誤

當雲端基礎結構上的Adobe Commerce部署失敗,出現​ 在'cache'名稱空間 ​錯誤中未定義任何命令,請識別這些設定中剩餘的無效列。 如果您只有一個網站,則網站的第二個測試不適用,您只需要測試商店。

說明 description

環境

雲端基礎結構上的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的設定。 當您從其他執行個體/環境匯入資料庫備份,而且這些範圍的設定仍保留在資料庫中時,即使關聯的存放區/網站已刪除,也會發生這種情況。

解決方法 resolution

如果您只有一個網站,則網站的第二個測試不適用,您只需要測試商店。

若要解決此問題,請識別這些設定中剩餘的無效列。

  1. SSH連線至伺服器並執行此命令:

    code language-none
    bin/magento
    
  2. 錯誤訊息可能會指出哪些資料列和資料表從刪除的網站保留在資料庫中。 例如,下列錯誤指出找不到要求的存放區:

    code language-none
    ...
        In StoreRepository.php line 112:
    
        The store that was requested wasn't found. Verify the store and try again.
    
  3. 執行此MySQL查詢以確認找不到存放區(由步驟2中的錯誤訊息所指示)。

    code language-none
    select distinct scope_id from core_config_data where scope='stores' and scope_id not in (select store_id from store);
    
  4. 執行下列MySQL敘述句來刪除無效的資料列:

    code language-none
    delete from core_config_data where scope='stores' and scope_id not in (select store_id from store);
    
  5. 再次執行此命令:

    code language-none
    bin/magento
    

    如果您收到類似以下錯誤的訊息,指出找不到所請求的ID為X的網站,則資料庫中會保留已刪除網站以及商店的設定。

    code language-none
    In WebsiteRepository.php line 110:
    
        The website with id X that was requested wasn't found. Verify the website and try again.
    

    執行此MySQL查詢,並確認找不到網站:

    code language-none
    select distinct scope_id from core_config_data where scope='websites' and scope_id not in (select website_id from store_website);
    
  6. 執行此MySQL陳述式,從網站組態中刪除無效的資料列:

    code language-none
    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