2

I am trying to have an admin module I am working on create a new table in the database. What I have setup in

app/code/local/Foo/BAR/sql/mysql4-install-0.1.0.php

<?php
  $installer = $this;
  $installer->startSetup();

  $installer->run("
    DROP TABLE IF EXISTS {$this->getTable('notes')};

    CREATE TABLE {$this->getTable('notes')} (
      `ppr_id` int(11) NOT NULL AUTO_INCREMENT,
      `notesku` bigint(20) NOT NULL,
      `notestatus`  smallint(16),
      PRIMARY KEY (`notes`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8
  ");

  $installer->endSetup();

and this in app/code/local/Foo/BAR/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Foo_BAR>
            <version>0.1.0</version>
        </Foo_BAR>
    </modules>    

    <global>
            <models>
                <BAR>
                    <class>Foo_BAR_Model</class>
                    <resourceModel>BAR_mysql4</resourceModel>
                </BAR>

                <BAR_myslq4>
                    <class>Foo_BAR_Model_Mysql4</class>
                    <entities>
                        <BAR>
                            <table>notes</table>
                        </BAR>
                    </entities>
                </BAR_myslq4>           
            </models>

            <resources>
                <BAR_setup>
                    <setup>
                        <module>Foo_BAR</module>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </BAR_setup>
                <BAR_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </BAR_write>
                <BAR_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </BAR_read>
            </resources>
    </global>    

    <admin>
        <routers>
            <BAR>
                <use>admin</use>
                <args>
                    <module>Foo_BAR</module>
                    <frontName>bar</frontName>
                </args>
            </BAR>      
        </routers>
    </admin>



      <adminhtml>
        <menu>
            <catalog>
                <children>
                     <BAR_menu translate="title" module="BAR">
                        <title>BAR</title>
                        <children>
                            <list translate="title" module="BAR">
                                <title>Bar</title>
                                <action>bar/index/index</action>
                            </list>                       
                        </children>
                    </BAR_menu>
                </children>
            </catalog>
        </menu>
    </adminhtml>       
</config>

The case I am using matches this example where my company is capitalized and the module name is all uppercase. I am thinking maybe that is tripping me up? My understanding is that once I run the page that hits that module it will trigger that mysql to create the table. Is that correct? Is there something else I should be doing?

I greatly appreciate any help with this.

4
  • Triggering any page should install your module since Magento triggers the module install/upgrade process before any routing takes place. If no tables are appearing the first thing to check is if your modules install script has ran, you can check then by checking the core_resources table in your database for a row having a code value of BAR_setup. Commented Jan 5, 2012 at 21:17
  • Thanks Cags. I checked the core_resources table and it is not showing up in there. Commented Jan 5, 2012 at 21:36
  • Did you create a file in app/etc/modules/ to enable your module? Commented Jan 5, 2012 at 21:50
  • Yes the module is working and I have other pages loading. This is something I am building on to it. Commented Jan 6, 2012 at 1:37

1 Answer 1

13

If a setup/upgrade script isn't running, here are some things to check:

  1. Is Magento loading your module? Go to System > Configuration > Advanced > Advanced and see if your module appears in the "Disable Module Output" list. If it doesn't, Magento isn't loading your module at all, and therefore won't run any setup scripts. As Cags noted in his comment, you'll need an xml file in app/etc/modules to tell Magento to load your module if you haven't already created one.

  2. Make sure your resources are declared in the correct place in the config.xml file. They should be inside the <global> tag (this appears to be correct in your case).

  3. Make sure your setup files are in the correct location. They should be in a sql/ folder inside your module. I think this is your problem, the setup file in this example should be app/code/local/Foo/BAR/sql/BAR_setup/mysql4-install-0.1.0.php

  4. Having checked all of the above, if you have an IDE set up for debugging (and if you're doing any serious Magento work, do yourself a favor and get one up), set a breakpoint in the setup file and make sure it's being hit.

  5. Check the core_resource table in the database for a BAR_setup entry. If it's there, Magento has run the setup script once and won't run it again. If you need to run your setup script again, delete this record. Likewise you can change the version numbers if you ever need to re-run upgrade scripts (but make sure you understand the consequences of running setup/upgrade scripts a second time if you do).

If all else fails check out Alan Storm's guide to debugging Magento setup scripts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.