How to create a UNIQUE column in magento install script

You can add unique columns in your install script easier than you thought. After searching for a while in search engines without any results, the good old method helped: search in all files of magento… The good news is that you get the results of my searches right here:

<?php
$installer = $this;
$installer->startSetup();
$table = $installer->getConnection()
->newTable($installer->getTable(SOME_TABLE_NAME_DEFINITION))

->addColumn(“my_unique_column_name”,…)

->addIndex($installer->getIdxName(SOME_TABLE_NAME_DEFINITION, array(‘my_unique_column_name’), Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE), “my_unique_column_name”,array(“type” => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE));
$installer->getConnection()->createTable($table);

$installer->endSetup();

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.