【问题标题】:Magento 2 addIndexMagento 2 添加索引
【发布时间】:2018-07-31 03:00:12
【问题描述】:

我是一个新的 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]
        );

我在运行 setup:upgrade 时收到的错误是

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`

不知道我在这里做错了什么。我可以看到它正在根据表名和我要索引的列的串联来查找表。

【问题讨论】:

    标签: magento magento2.2


    【解决方案1】:

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

     $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
    );
    

    【讨论】:

    • 我对答案进行了更改,您可以试试这个吗?
    • 没问题,我更新了答案以保留正确的解决方案,删除了旧的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2021-09-11
    • 2016-02-02
    • 1970-01-01
    • 2018-12-22
    相关资源
    最近更新 更多