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/…Fran Mayers– Fran Mayers2016年11月25日 11:27:29 +00:00Commented Nov 25, 2016 at 11:27
-
Is there any way if I want to upgrade core file and core module for this? @MayersKazim Noorani– Kazim Noorani2016年11月25日 11:37:27 +00:00Commented Nov 25, 2016 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)Fran Mayers– Fran Mayers2016年11月25日 11:44:13 +00:00Commented Nov 25, 2016 at 11:44
-
Thank you dear! I tried your words and it works. @MayersKazim Noorani– Kazim Noorani2016年11月25日 11:59:06 +00:00Commented Nov 25, 2016 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 postFran Mayers– Fran Mayers2016年11月25日 15:12:32 +00:00Commented Nov 25, 2016 at 15:12
3 Answers 3
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)