2

您好,我刚刚将一个项目从 magento 2.2.6 升级到 2.3,并且在进行设置时遇到了这个问题:升级

SQLSTATE [42S02]:未找到基表或视图:1146 表 'catalog_category_product_index_store1_store1' 不存在,查询为:INSERT INTO catalog_category_product_index_store1_store1 ( category_id, product_id, position, is_parent, store_id, visibility) SELECT catalog_category_product_index_store1.* FROM catalog_category_product_index_store1WHERE (store_id = '1') ON DUPLICATE KEY UPDATE category_id= 值( category_id), product_id= 值( product_id), position= 值( position), is_parent= 值( is_parent), store_id= 值( store_id), visibility= 值( visibility)

4

1 回答 1

3

我找到了根本原因:

有一个插件 (Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver) 将 _store1 后缀添加到 $setup->getTable() 调用中。这对主应用程序非常有用,但是在首次创建 _storeX 表时运行的数据迁移期间也使用了 $setup->getTable() ,我们需要原始表名来运行该迁移。

我通过覆盖迁移数据补丁解决了这个问题:Magento\Catalog\Setup\Patch\Data\EnableSegmentation.php

请执行下列操作:

  1. 为此覆盖创建一个新模块或使用现有模块。有许多在线创建模块的演练。

  2. 将 Magento\Catalog\Setup\Patch\Data\EnableSegmentation.php 复制到模块中的相同路径。因此,如果您的模块位于 app\code\Company\PatchFix 中,您需要将文件复制到 app\code\Company\PatchFix\Setup\Patch\Data\EnableSegmentation.php。

  3. 在复制的文件中,更新第 7 行中的命名空间:

namespace Company\PatchFix\Setup\Patch\Data;
  1. 在 $setup 对象被定义后添加以下代码(大约第 58 行):
        // Get the index table name once
        $catalogCategoryProductIndexTableName = $setup->getTable('catalog_category_product_index');
        // This table name will probably not end with _index, but we need it to for this patch to work
        if (substr($catalogCategoryProductIndexTableName, -5) !== 'index') {
            while (substr($catalogCategoryProductIndexTableName, -5) !== 'index') {
                $catalogCategoryProductIndexTableName = substr($catalogCategoryProductIndexTableName, 0,
                    strlen($catalogCategoryProductIndexTableName) - 1);
            }
        }

它只是一次一个地从表名中删除结束字符,直到以 . 结尾index

  1. $setup->getTable('catalog_category_product_index')用替换所有以后的调用$catalogCategoryProductIndexTablename

  2. 保存您的更改。

  3. 如果您的模块没有etc/di.xml文件,请从头开始创建一个或从另一个模块复制一个。同样,在线提供指南可向您展示如何执行此操作。

  4. 为您的新数据补丁添加覆盖首选项:

    <preference for="Magento\Catalog\Setup\Patch\Data\EnableSegmentation" type="Company\PatchFix\Setup\Patch\Data\EnableSegmentation" />
  1. 保存 etc/di.xml。

  2. 运行setup:upgrade

于 2019-11-12T16:37:14.830 回答