ivn
ivn

Reputation: 1275

Magento Install script never runs

I am trying to create a custom table using custom module. I have been following Alan Storm's article to create a custom table

This is my folder structure

CM
 Tablecreation
 etc >> config.xml (has 1.6.0.0 as the version mentioned)
 Helper >> Data.php
 controllers >> IndexController.php
 Model
  Actualtable.php
  Mysql4
   Actualtable.php
  Resource
   Mysql4
     Setup.php
  sql
   tablecreation_setup
     install-1.6.0.0.php

This is my config.xml file.

  <?xml version="1.0" encoding="UTF-8"?>
  <config>
  <modules>
    <CM_Tablecreation>
        <version>1.6.0.0</version>
    </CM_Tablecreation>
</modules>
<frontend>
    <routers>
        <tablecreation>
            <use>standard</use>
            <args>
                <module>CM_Tablecreation</module>
                <frontName>tablecreation</frontName>
            </args>
        </tablecreation>
    </routers>
</frontend>    
<global>

    <models>
        <tablecreation>
            <class>CM_Tablecreation_Model</class>
            <resourceModel>tablecreation_mysql4</resourceModel>
        </tablecreation>
        <tablecreation_mysql4>
        <class>CM_Tablecreation_Model_Mysql4</class>     
        <entities>
            <actualtable>
                <table>actual_table</table>
            </actualtable>
        </entities>                    
    </tablecreation_mysql4>
    </models>

    <resources>
    <tablecreation_setup>
    <setup>
        <module>CM_Tablecreation</module>
        <class>CM_Tablecreation_Model_Resource_Mysql4_Setup</class>
    </setup>
    <connection>
        <use>core_setup</use>
    </connection>
    </tablecreation_setup>
    <tablecreation_write>
        <connection>
            <use>core_write</use>
        </connection>
    </tablecreation_write>
    <tablecreation_read>
        <connection>
            <use>core_read</use>
        </connection>
    </tablecreation_read>      
</resources>      

    <helpers>
            <tablecreation>
                <class>CM_Tablecreation_Helper</class>
            </tablecreation>
    </helpers>
</global>
</config>

And this is the error I get every time

  a:5:{i:0;s:69:"/home/dev/public_html/app/code///sql/tablecreation_setup not found";i:1;s:818:"#0 /home/dev/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(421): Mage_Core_Model_Resource_Setup->_modifyResourceDb('install', '', '1.6.0.0')

I tried debugging by putting try catch with exception messages in app/code/core/Mage/Core/Resource/Setup.php as suggested in some of the previous similar questions on this topic, but to no success

My module isn't even getting listed in core_resource table. And even if some how it does, the table surely never gets created.

I have also had the situation when it did list in core_resource table but If I delete my module's record from the table (to run install script again) and then try to refresh any page of my site I again end up getting error page opening the report of which I find the same error.

Basically any article over the net I follow, I get stuck at this same error. Please help me explain this error and what's causing it. Probably also if some one can suggest what's the solution to sort it.

Many thanks in advance.

Upvotes: 2

Views: 4107

Answers (1)

Jim OHalloran
Jim OHalloran

Reputation: 5918

I can see a couple of issues with what you've posted:

  1. Your install script needs to be called mysql4-install-1.6.0.0.php. If Magento can't find the setup script because it's named incorrectly, it won't be able to run it, so I'd rename your install-1.6.0.0.php to mysql4-install-1.6.0.0.php.

  2. You'll need a resources tag in the global section in your config.xml file which looks like this:

    <resources>
        <tablecreation_setup>
            <setup>
                <module>CM_Tablecreation</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </tablecreation_setup>
    </resources>
    
  3. Check your app/etc/modules.CM_Tablecreation.xml file. The error message you've posted is interesting in that the code pool and module name is missing from the path where it's attempting tom locate the setup file. Check that your xml file has a config > modules > YourModule_NameHere > codePool tag (note codePool with a capital P) which contains the string "core", "community" or "local" depending on the location in which your module resides.

You may find some assistance in my previous answer to a similar question, and Alan Storm's definitive answer on the subject.

PS: Your extension version doesn't need to be the same version number as Magento itself. Just start with whatever version number makes you happy and increment as required.

Upvotes: 2

Related Questions