2

How to create More then one table in magento with installer script ?

  • 1
    Just like you create one table create the other. See an example of how multiple tables are created in the same install script in app/code/core/Mage/Cms/sql/cms_setup/install-1.6.0.0.php – Marius Dec 19 '14 at 11:56
4

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();
| improve this answer | |
  • is there any change in config.xml – Vaibhav Ahalpara Dec 19 '14 at 12:53
  • 1
    you have to change your table name and fields name only. – Abhishek Gupta Dec 19 '14 at 13:06
  • can you explain in brief ? – Vaibhav Ahalpara Dec 19 '14 at 13:36
  • 1
    Yes, you need to define model & resource node in config.xml file inside global tag. Your multiple table name pass on inside entities tag – Abhishek Gupta Dec 20 '14 at 8:48
  • 1
    <entities><page><table>cms_page</table></page><page_store><table>cms_page_store</table></page_store></entities> – Abhishek Gupta Dec 20 '14 at 8:49

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.