Magento 2 addIndex
我是一个新的Magento用户,正在尝试使用UpgradeSchema.php将基于2列的唯一数据库索引添加到自定义数据库表中。该表已存在,我正在索引的列也已存在。以下是我的代码部分:Magento 2 addIndex,magento,magento2.2,Magento,Magento2.2,我是一个新的Magento用户,正在尝试使用UpgradeSchema.php将基于2列的唯一数据库索引添加到自定义数据库表中。该表已存在,我正在索引的列也已存在。以下是我的代码部分: $installer->getConnection() ->addIndex( $installer->getIdxName( $installer->getTable('ds_runs'),
$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
);
我对我的答案做了修改,你能试试吗?没问题,我更新了答案,只保留了正确的答案,删除了旧的答案。