2

I'm a new Magento user and am trying to add a unique database index based on 2 columns to a custom database table using UpgradeSchema.php. The table already exists as do the columns I'm indexing. Here is my code portion:

$installer->getConnection()
        ->addIndex(
            $installer->getIdxName(
                $installer->getTable('ds_runs'),
                ['date_delivery', 'run'],
                AdapterInterface::INDEX_TYPE_UNIQUE
            ),
            ['date_delivery', 'run'],
            ['type' => AdapterInterface::INDEX_TYPE_UNIQUE]
        );

The error I receive when running setup:upgrade is

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`

Don't know what I'm doing wrong here. I can see it's looking for a table based on a concatenation of the table name and the columns I want to index.

mentalist
  • 33
  • 6

1 Answers1

2

UPDATE: This is the correct solution:

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