0

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();
?>
  • check in core_resource table in the database, do you have any row there for test_setup? – Piyush Oct 17 '17 at 8:32
  • I ran this query on mysql SELECT * FROM core_resource WHERE code='test_setup'; and it returned 0 – Abhilash Narayan Oct 17 '17 at 8:37
  • it means that your sql file did not ran, check your module is enabled and have Abhi_Test.xml under app/etc directory – Piyush Oct 17 '17 at 8:40
  • @AbhilashNarayan why are you keeping quotes to column names? 'test_id', 'title' like this? – Teja Bhagavan Kollepara Oct 17 '17 at 8:41
  • I do have Abhi_Test.xml file in app/etc/modules/Abhi_Test.xml and its enabled. @Piyush – Abhilash Narayan Oct 17 '17 at 8:43
0

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.

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.