2

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

1
  • 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
    Commented Dec 19, 2014 at 11:56

1 Answer 1

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();
6
  • is there any change in config.xml Commented Dec 19, 2014 at 12:53
  • 1
    you have to change your table name and fields name only. Commented Dec 19, 2014 at 13:06
  • can you explain in brief ? Commented Dec 19, 2014 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 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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