I have created file mysql4-upgrade-1.6.0.1-1.6.0.2 in which code is like,

<?php
$installer = $this;
$installer->startSetup();

$installer->getConnection()
->addColumn($installer->getTable('newsletter_subscriber'),'subscriber_name', array(
    'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
    'length'    => 255,
    'after'     => 'subscriber_email', // column name to insert new column after
    'comment'   => 'Subscriber Name'
    ));   
$installer->endSetup();
?>

Also changed in config file. It is like,

<modules>
        <Mage_Newsletter>
            <version>1.6.0.2</version>
        </Mage_Newsletter>
</modules>

But still column is not added in the database 'newsletter_subscriber' table. Any help?

  • Don't edit Magento core files directly; Have a look there, it tells you how to create setup files for custom modules: inchoo.net/magento/… – Mayers Nov 25 '16 at 11:27
  • Is there any way if I want to upgrade core file and core module for this? @Mayers – Kazim Noorani Nov 25 '16 at 11:37
  • you need to create a custom module, and in the setup file of this custom module you can modify core tables. The only reason for this, is that a Magento upgrade would wipe your changes (The link above gives you a detailed tutorial about how to create this module) – Mayers Nov 25 '16 at 11:44
  • Thank you dear! I tried your words and it works. @Mayers – Kazim Noorani Nov 25 '16 at 11:59
  • great news! I have added my comment as a response, if it's helped you, please mark it as accepted so we can close off this post – Mayers Nov 25 '16 at 15:12

If above syntax is not working for you then you can try below syntax to

<?php
$installer = $this;


$installer->startSetup();

try {
        $tableName = $installer->getTable('newsletter_subscriber');
        $installer->run(" ALTER TABLE {$tableName} ADD `subscriber_email` VARCHAR(255) NOT NULL  ; ");
        $installer->endSetup();


} catch (Exception $e) {
        // to do
}

and also check your core_resource table if entry is already there for your new version then revert and try again

Try this :

<?php
$installer = $this;
$installer->startSetup();

$installer->getConnection()
->addColumn($installer->getTable('newsletter/subscriber'),
'subscriber_name', 
array(
    'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
    'length'    => 255,
    'after'     => 'subscriber_email', // column name to insert new column after
    'comment'   => 'Subscriber Name'
    ));   
$installer->endSetup();
?> 

Don't edit Magento core files directly; Have a look there, it tells you how to create setup files for custom modules: http://inchoo.net/magento/magento-install-install-upgrade-data-and-data-upgrade-scripts/

You need to create a custom module, and in the setup file of this custom module you can modify core tables. The only reason for this, is that a Magento upgrade would wipe your changes (The link above gives you a detailed tutorial about how to create this module)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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