1

We are using the Extension FollowUp E-Mail from AheadWorks. The Extension has bugs in the sql install scripts... they are trying to add a column to a table but don't check if the column does already exist, which causes an error if the column already exists.

<?php
$installer = $this;

/* $installer Mage_Core_Model_Resource_Setup */

$installer->startSetup();
$installer->run("
    ALTER TABLE {$this->getTable('awcore/logger')} ADD `custom_field_4` VARCHAR( 255 ) NOT NULL AFTER `custom_field_3`;
    ALTER TABLE {$this->getTable('awcore/logger')} ADD INDEX ( `custom_field_4` );
");
$installer->endSetup();

I get this error :

a:5:{i:0;s:197:"Error in file: "/srv/www/vhosts/hf/app/code/local/AW/Core/sql/awcore_setup/mysql4-upgrade-1.0.1-1.0.2.php" - SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'custom_field_4'
/srv/www/vhosts/hausfux/app/code/core/Mage/Core/Model/Resource/Setup.php(644
#1 /srv/www/vhosts/hf/app/code/core/Mage/Core/Model/Resource/Setup.php(437): Mage_Core_Model_Resource_Setup->_modifyResourceDb('upgrade', '1.0.1', '1.0$
#2 /srv/www/vhosts/hf/app/code/core/Mage/Core/Model/Resource/Setup.php(320): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('1.0.1', '1.0.3')
#3 /srv/www/vhosts/hf/app/code/core/Mage/Core/Model/Resource/Setup.php(235): Mage_Core_Model_Resource_Setup->applyUpdates()
#4 /srv/www/vhosts/hf/app/code/core/Mage/Core/Model/App.php(428): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#5 /srv/www/vhosts/hf/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Model_App->_initModules()
#6 /srv/www/vhosts/hf/app/Mage.php(690): Mage_Core_Model_App->run(Array)
#7 /srv/www/vhosts/hf/index.php(70): Mage::run('', 'store')
#8 {main}";s:3:"url";s:1:"/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
0

You should use the tableColumnExist method :

$tableName = 'your_table';
$columnName = 'your_column';
if (!$installer->getConnection()->tableColumnExists($installer->getTable($tableName), $columnName)) {
    // create your column
}
  • I will try it out later and let you know, thx so far! – Black May 23 '19 at 14:14
0

You can try like this

$tableName = $this->getTable('awcore/logger');
$installer->startSetup();
$connection = $installer->getConnection();
if ($connection->tableColumnExists($tableName, 'custom_field_4') === false) {
        $connection
          ->addColumn(
               $setup->getTable($tableName),
               'custom_field_4',
              [
                  'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                  'nullable' => false
              ]
          );
   }
  • I will try it out later and let you know, thx so far! – Black May 23 '19 at 14:14

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.