0

I am trying to create a script to create a table in my custom module. I tried many method but i thing there is a minor issue in my script. I want sure what is mistake.

Config file

Path - app\code\community\Amit\Custommodule\etc\config.xml

<?xml version="1.0" ?>
<config>
   <modules>
      <Amit_Custommodule>
         <version>1.1.0</version>
      </Amit_Custommodule>
   </modules>
 <global>
<models>
    <custommodule>
        <class>Amit_Custommodule_Model</class>
        <resourceModel>custommodule_resource</resourceModel>
    </custommodule>
    <custommodule_resource>
        <entities>
            <custommodule>
                <table>custommodule</table>
            </custommodule>
            <custommodule>
                <table>custommodule2</table>
            </custommodule>             
            <custommodule>
                <table>custommodule3</table>
            </custommodule>
        </entities>
    </custommodule_resource>
</models>
<resources>
    <custommodule_setup>
        <setup>
            <module>Amit_Custommodule</module>
            <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </custommodule_setup>
    <custommodule_read>
        <connection>
            <use>core_read</use>
        </connection>
    </custommodule_read>
    <custommodule_write>
        <connection>
            <use>core_write</use>
        </connection>
    </custommodule_write>
</resources>
<!-- start of block -->
<blocks>
    <custommodule>
        <class>Amit_Custommodule_Block</class>
    </custommodule>
</blocks>

standard Amit_Custommodule custommodule custommodule.xml Sql Query

Path - app\code\community\Amit\Custommodule\sql\custommodule_setup\upgrade-1.0.0-1.1.0.php

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

$installer->run("
-- DROP TABLE IF EXISTS {$this->getTable('custommodule3')};
CREATE TABLE {$this->getTable('custommodule3')} (
  `custommodule_id` int(11) unsigned NOT NULL auto_increment COMMENT 'Q&A ID',
  `product_id` int(11) NOT NULL  COMMENT 'Product Id' ,
  `customer_name` varchar(255) NOT NULL COMMENT 'Customer Name',
  `customer_email` varchar(255) NOT NULL  COMMENT 'Customer Email',
  `question` text NOT NULL  COMMENT 'Question',
  `answer` text NOT NULL  COMMENT 'Answer',
  `status` smallint(6) NOT NULL default '0' COMMENT 'Status',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`custommodule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ");
$installer->endSetup();
?>
0

In your config.xml change below code

<models>
    <custommodule>
    <class>Amit_Custommodule_Model</class>
    <resourceModel>custommodule_resource</resourceModel>
    </custommodule>
    <custommodule_resource>
    <entities>
        <custommoduleone>
            <table>custommodule</table>
        </custommoduleone>
        <custommoduletwo>
            <table>custommodule2</table>
        </custommoduletwo>             
        <custommodulethree>
            <table>custommodule3</table>
        </custommodulethree>
    </entities>
    </custommodule_resource>
</models>

and in your upgrade-1.0.0-1.1.0.php

change getTable param

$this->getTable('custommodule/custommodulethree');
|improve this answer|||||

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.