Magento 1.9 – Custom Table Not Getting Created

magento-1.9table

I am unable to find why the table is not getting created. I have cleared the cache and everything and checked for the solutions but everything seems good.

Here is my config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <version>3.0.0</version>
    </modules>
    <frontend>
        <routers>
            <test>
                <use>standard</use>
                <args>
                    <module>Abhi_Test</module>
                    <frontName>test</frontName>
                </args>
            </test>
        </routers>
        <layout>
            <updates>
                <test>
                    <file>test.xml</file>
                </test>
            </updates>
        </layout>
    </frontend>
    <global>
        <models>
            <test>
                <class>Abhi_Test_Model</class> <!-- Location of all model class files -->
                <resourceModel>test_mysql4</resourceModel> <!-- Location of resource model -->
            </test>
            <test_mysql4>
                <class>Abhi_Test_Model_Mysql4</class>
                <entities>
                    <test>
                        <table>test_tablename</table> <!-- Actual table name in sql -->
                    </test>
                </entities>
            </test_mysql4>
        </models>
        <resources> <!-- These are resource setting giving access to module, read/write permission on database -->
            <test_setup>
                <setup>
                    <module>Abhi_Test</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </test_setup>
            <test_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </test_write>
            <test_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </test_read>
        </resources>
        <blocks>
             <test>
                <class>Abhi_Test_Block</class>
            </test>
        </blocks>
        <helpers>
            <test>
                <class>Abhi_Test_Helper</class>
            </test>
        </helpers>
    </global>
</config>

I have created a Model in

app\code\local\Abhi\Test\Model\Test.php

<?php
class Abhi_Test_Model_Test extends Mage_Core_Model_Abstract {
    public function _construct() {
        parent::_construct();
        $this->_init('test/test');  //This is location of the resource file
    }
}
?>

I have created resource at

App\Code\Local\Abhi\Test\Model\Mysql4\Test.php

<?php
class Abhi_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract {
    public function _contruct() {
        $this->_init('test/test', 'test_id');   /*here test_id is the primary of the table test. And test/test, is the magento table name as mentioned in the config.xml */
    }
}
?>

I have created installer file at

App\Code\Local\Abhi\Test\sql\test_setup\mysql4-install-3.0.0.php

<?php
$installer = $this;  //Getting Installer Class Object In A Variable
$installer->startSetup()
$installer->run("
CREATE TABLE {$this->getTable('test/test')} (
  `test_id` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `filename` varchar(255) NOT NULL default '',
  `content` text NOT NULL default '',
  `status` smallint(6) NOT NULL default '0',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();
?>

Best Answer

I found out what mistake I have done and here it is: I made a mistake in my config.xml file

<modules>
    <Abhi_Test>
        <version>3.0.0</version>
    </Abhi_Test>
</modules>

I was missing the <Abhi_Test> tag.

Related Topic