1

Here i am trying to create unique key using installSchema . Array of column names is defined here on which columns combinedly i want to apply unique key

$arrayOfColumnsName = array('column1', 'column2');

here defined the addIndex method for creating the unique key

->addIndex(
            $installer->getIdxName(
                $installer->getTable('table_name'),
                $arrayOfColumnsName,
               \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
            ),
            $arrayOfColumnsName,
            ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
        )

This creates unique key for only first column instead of both columns, needs help for the same

2

Try This :-

->addIndex(
            $installer->getIdxName(
                $installer->getTable('table_name'),
                ['column1','column2'],
               \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
            ),
           ['column1','column2'],
            ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
        )
0

Change the format of your $arrayOfColumnsName data like this:

$arrayOfColumnsName = ['column1', 'column2']  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.