我找到了根本原因:
有一个插件 (Magento\Catalog\Model\Indexer\Category\Product\Plugin\TableResolver) 将 _store1 后缀添加到 $setup->getTable() 调用中。这对主应用程序非常有用,但是在首次创建 _storeX 表时运行的数据迁移期间也使用了 $setup->getTable() ,我们需要原始表名来运行该迁移。
我通过覆盖迁移数据补丁解决了这个问题:Magento\Catalog\Setup\Patch\Data\EnableSegmentation.php
请执行下列操作:
为此覆盖创建一个新模块或使用现有模块。有许多在线创建模块的演练。
将 Magento\Catalog\Setup\Patch\Data\EnableSegmentation.php 复制到模块中的相同路径。因此,如果您的模块位于 app\code\Company\PatchFix 中,您需要将文件复制到 app\code\Company\PatchFix\Setup\Patch\Data\EnableSegmentation.php。
在复制的文件中,更新第 7 行中的命名空间:
namespace Company\PatchFix\Setup\Patch\Data;
- 在 $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
。
$setup->getTable('catalog_category_product_index')
用替换所有以后的调用$catalogCategoryProductIndexTablename
。
保存您的更改。
如果您的模块没有etc/di.xml
文件,请从头开始创建一个或从另一个模块复制一个。同样,在线提供指南可向您展示如何执行此操作。
为您的新数据补丁添加覆盖首选项:
<preference for="Magento\Catalog\Setup\Patch\Data\EnableSegmentation" type="Company\PatchFix\Setup\Patch\Data\EnableSegmentation" />
保存 etc/di.xml。
运行setup:upgrade
。