5

I am doing a module in Magento (1.7.2). In that module, I want to create a database table. I have used all the codes properly. But still, I can't see the database table in phpMyAdmin.

In /app/etc/modules/Myfolder_Storeinfo.xml the module info is like this :

<?xml version="1.0"?>
<config>
  <modules>
    <Myfolder_Storeinfo>
      <active>true</active>
      <codePool>community</codePool>
    </Myfolder_Storeinfo>
  </modules>
</config> 

In IndexController.php file inside path /app/code/community/Myfolder/Storeinfo/controllers/IndexController.php is like this :

class Myfolder_Storeinfo_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
            $this->loadLayout();
            $this->renderLayout();
    }
}

Now the module configuration file configuration XML (config.xml) the path is /app/code/community/Myfolder/Storeinfo/etc/config.xml is like this :

<?xml version="1.0"?>
<config>
    <modules>
        <Myfolder_Storeinfo>
            <version>0.1.1</version>
        </Myfolder_Storeinfo>
    </modules>

    <frontend>
        <routers>
            <storeinfo>
                <use>standard</use>
                <args>
                    <module>Myfolder_Storeinfo</module>
                    <frontName>storeinfo</frontName>
                </args>
            </storeinfo>
        </routers>
        <translate>
            <modules>
                <Myfolder_Storeinfo>
                    <files>
                        <default>Myfolder_Storeinfo.csv</default>
                    </files>
                </Myfolder_Storeinfo>
            </modules>
        </translate>
        <layout>
            <updates>
                <question>
                    <file>storeinfo.xml</file>
                </question>
            </updates>
        </layout>
    </frontend>

    <admin>
        <routers>
            <storeinfo>
                <use>admin</use>
                <args>
                    <module>Myfolder_Storeinfo</module>
                    <frontName>storeinfo</frontName>
                </args>
            </storeinfo>
        </routers>
    </admin>

    <adminhtml>
        <menu>
            <storeinfo module="storeinfo">
                <title>Storeinfo</title>
                <sort_order>71</sort_order>               
                <children>
                    <items module="storeinfo">
                        <title>Storeinfo</title>
                        <sort_order>0</sort_order>
                        <action>storeinfo/adminhtml_storeinfo</action>
                    </items>
                </children>
            </storeinfo>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <Myfolder_Storeinfo>
                            <title>Storeinfo Module</title>
                            <sort_order>10</sort_order>
                        </Myfolder_Storeinfo>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <storeinfo>
                    <file>storeinfo.xml</file>
                </storeinfo>
            </updates>
        </layout>
    </adminhtml>

    <global>
        <models>
            <storeinfo>
                <class>Myfolder_Storeinfo_Model</class>
                <resourceModel>storeinfo_mysql4</resourceModel>
            </storeinfo>
            <storeinfo_mysql4>
                <class>Myfolder_Storeinfo_Model_Mysql4</class>
                <entities>
                    <storeinfo>
                        <table>Myfolder_storeinfo</table>
                    </storeinfo>
                </entities>
            </storeinfo_mysql4>
        </models>
        <resources>
            <storeinfo_setup>
                <setup>
                    <module>Myfolder_Storeinfo</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </storeinfo_setup>
            <storeinfo_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </storeinfo_write>
            <storeinfo_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </storeinfo_read>
        </resources>
        <blocks>
            <storeinfo>
                <class>Myfolder_Storeinfo_Block</class>
            </storeinfo>
        </blocks>
        <helpers>
            <storeinfo>
                <class>Myfolder_Storeinfo_Helper</class>
            </storeinfo>
        </helpers>
    </global>
</config>

For creating database table my code for mysql4-install-0.1.0.php the path is /community/MyFolder/Storeinfo/sql/storeinfo_setup/mysql4-install-0.1.0.php is like this :

<?php

$installer = $this;

$installer->startSetup();

$installer->run("
DROP TABLE IF EXISTS {$this->getTable('Myfolder_storeinfo')};
CREATE TABLE {$this->getTable('Myfolder_storeinfo')} (
  `storeinfo_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL DEFAULT '',
  `description` text NOT NULL,
  `status` char(1) NOT NULL DEFAULT '0',
  `created_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`storeinfo_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
");

$installer->endSetup(); 

But after all, I can't see my module is creating any table. From Magento admin I can see my module is enabled from System->Configuration->Advanced->Advanced->Disable Modules Output->Myfolder_Storeinfo -> enable. So can someone kindly tell me where is the wrong part then? Any help and suggestions will be really appreciable. Thanks

7 Answers 7

15

There are a few things you can check/ should do to make sure it works.

  • Check in the database table core_resources if your extension was added and with what version
  • Add a die to your installer to check if the installer is called at all
  • Since <table>Myfolder_storeinfo</table> is the actual MySQL table name please make it lowercase
6

Rename the file mysql4-install-0.1.0.php to install-0.1.1.php

Delete the setup entry (for this module) in core_resource table

Disable the cache.

Refresh any page

Check the database

5

This is an old question but I want to share this.

If you have triple checked that:

  1. your module version is the right one
  2. your install / data script filename is ok
  3. you have really flushed the cache

Then try to disable all caches. I've seen a case where flushing the cache (by deleting the files or with php cache.php destroy) was not enough.

Disabling all caches made the module appear in the core_resource table instantly.

3

Use storeinfo/storeinfo instead of Myfolder_storeinfo in mysql4-install-0.1.0.php

3
  • This is the right answer. Jul 10, 2015 at 6:56
  • Could you give a bit more details for your answer, as in "why" it seems to be the best solution? Jul 10, 2015 at 7:40
  • The getTable takes the group/name argument, it references to the associated setup defined in config.xml. Calling getTable('storeinfo/storeinfo') finds the <model><storeinfo> node, in there you have defined a reference to the <storeinfo_resource> node, which contains the <entities><storeview> node with the table name. There's not much to explain, it's simply how Magento works.
    – Jacques
    Dec 7, 2016 at 16:29
2

You need to check this condition if you are facing this type of problem.

  1. <version>0.1.1</version> mysql4-install-0.1.0.php // There 0.1.1 and -install-version(0.1.0) should be same
  2. check compilation disable or not. In order to run installer script you must have to make compilation disable.
  3. Check core_resource table and make a search on code column for your extension entry. If found then delete it
  4. Delete cache

This steps always work for me!

2

I have checked your code on Magento CE 1.7 and it is working fine and creating a table in the database.
Please check if there is any database related issue or any write permission issue.
You can try creating a table from phpMyAdmin and then using plain PHP and check you are able to successfully create a table.

1

Your version is off. config.xml has <version>0.1.1</version>

but your script is in mysql4-install-0.1.0.php

Fix that then check the detail from Sander

2
  • 1
    If the version on the install file is lower than the version specified in the config file the install script should still run at first install.
    – Marius
    Sep 26, 2013 at 12:10
  • Ah that makes sense. thks
    – Dan
    Sep 26, 2013 at 12:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.