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

Andhi Irawan
9821 gold badge14 silver badges28 bronze badges
asked Sep 26, 2013 at 11:03

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
answered Sep 26, 2013 at 11:10
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

answered Oct 15, 2013 at 10:05
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.

answered Feb 1, 2017 at 21:23
3

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

Amit Bera
77.8k21 gold badges127 silver badges240 bronze badges
answered Jul 10, 2015 at 6:51
3
  • This is the right answer. Commented 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? Commented 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. Commented 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!

answered Apr 8, 2016 at 14:23
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.

Andhi Irawan
9821 gold badge14 silver badges28 bronze badges
answered Sep 29, 2013 at 2:18
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

answered Sep 26, 2013 at 12:08
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. Commented Sep 26, 2013 at 12:10
  • Ah that makes sense. thks Commented Sep 26, 2013 at 12:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.