1

I am new in magento. I need to create my own module (or) extension in Magento. In my module, table cannot be created in the magento table. I am using this code.

File:/app/code/local/com_name/module_name/sql/module_setup/mysql4_install-0.1.0.php
 $installer = $this;
  $installer->startSetup();

  $installer->run("
    DROP TABLE IF EXISTS {$this->getTable('th_tweet')};

    CREATE TABLE {$this->getTable('th_tweet')} (
      `tweet_id` int(11) NOT NULL AUTO_INCREMENT,
      `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `twitter_id` bigint(20) NOT NULL,
      `text` text NOT NULL,
      PRIMARY KEY (`tweet_id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1
  ");

  $installer->endSetup();

then, config.xml file can be called like this,

<models>
        <tweet>
            <class>TechAndHouse_Tweet_Model</class>
            <resourceModel>tweet_mysql4</resourceModel>
        </tweet>

            <tweet_mysql4>
                  <class>TechAndHouse_Tweet_Model_Mysql4</class>
                  <entities>
                        <tweet>
                              <table>th_tweet</table>
                        </tweet>
                  </entities>
            </tweet_mysql4>
      </models>

I was creating tabs in admin panel and the front end block was createded but i can not create a table for my custom module. How to create a table for my custom module?

Any help would be appreciated.

1 Answer 1

5

Add resources section to your config.xml, global

<global>
    ...
    <resources>
        <tweet_setup>
            <setup>
                <module>TechAndHouse_Tweet</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </tweet_setup>
        <tweet_write>
            <connection>
                <use>core_write</use>
            </connection>
        </tweet_write>
        <tweet_read>
            <connection>
                <use>core_read</use>
            </connection>
        </tweet_read>
    </resources>
    ...
</global>
Sign up to request clarification or add additional context in comments.

2 Comments

thank u @magalter..i put in my config.xml file..but 404 error in frontend and no table create in database...
i will refer this link for creating module....amitsamtani.com/2011/03/18/writing-a-custom-module-in-magento

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.