Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 2 addIndex_Magento_Magento2.2 - Fatal编程技术网

Magento 2 addIndex

Magento 2 addIndex,magento,magento2.2,Magento,Magento2.2,我是一个新的Magento用户,正在尝试使用UpgradeSchema.php将基于2列的唯一数据库索引添加到自定义数据库表中。该表已存在,我正在索引的列也已存在。以下是我的代码部分: $installer->getConnection() ->addIndex( $installer->getIdxName( $installer->getTable('ds_runs'),

我是一个新的Magento用户,正在尝试使用UpgradeSchema.php将基于2列的唯一数据库索引添加到自定义数据库表中。该表已存在,我正在索引的列也已存在。以下是我的代码部分:

$installer->getConnection()
        ->addIndex(
            $installer->getIdxName(
                $installer->getTable('ds_runs'),
                ['date_delivery', 'run'],
                AdapterInterface::INDEX_TYPE_UNIQUE
            ),
            ['date_delivery', 'run'],
            ['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
        );
运行安装程序:升级时收到的错误为

Base table or view not found: 1146 Table 'doorstep.ds_runs_date_delivery_run_run_id' 
doesn't exist,query was:DESCRIBE `DS_RUNS_DATE_DELIVERY_RUN_RUN_ID`
不知道我做错了什么。我可以看到它正在根据表名和要索引的列的串联查找表。

更新: 这是正确的解决方案:

 $installer->getConnection()
    ->addIndex(
            $installer->getTable('ds_runs'),
            $installer->getConnection()->getIndexName($installer->getTable('ds_runs'), ['date_delivery', 'run'], Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE),
    ['date_delivery', 'run'],
   Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
);

我对我的答案做了修改,你能试试吗?没问题,我更新了答案,只保留了正确的答案,删除了旧的答案。