How to create More then one table in magento with installer script ?
1 Answer
Below code is use for creating multiple tables in installer scrips.
<?php
$installer = $this;
$installer->startSetup();
$table = $installer->getConnection()
->newTable($installer->getTable('module_learning/basedata'))
->addColumn('ticket_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'Id')
->addColumn('title', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
'nullable' => false,
), 'Title')
->addColumn('description', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
'nullable' => false,
), 'Description');
$installer->getConnection()->createTable($table);
$table = $installer->getConnection()
->newTable($installer->getTable('module_learning/comment'))
->addColumn('comment_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'Id')
->addColumn('comment', Varien_Db_Ddl_Table::TYPE_VARCHAR, null, array(
'nullable' => false,
), 'Comment');
$installer->getConnection()->createTable($table);
$installer->endSetup();
-
-
1you have to change your table name and fields name only. Commented Dec 19, 2014 at 13:06
-
-
1Yes, you need to define model & resource node in config.xml file inside global tag. Your multiple table name pass on inside entities tag Commented Dec 20, 2014 at 8:48
-
1<entities><page><table>cms_page</table></page><page_store><table>cms_page_store</table></page_store></entities> Commented Dec 20, 2014 at 8:49
app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php