Magento – adding a new table to the database

databaseinstall

I have an install script for a module which Ive been working on that has previously run perfectly. Since I last used it I have deleted the database, in which it was installed and now want to reuse it.

I accessed the relevant module in my browser then checked my database, the table i am trying to install does not seem to install. I have looked in core_resource to see if there is a record of it in there, but there is no record.

It is my understanding that magento will look at the version number in the config file and compare that to the install file version number and if the version number of the config is greater than the version number of the install file it will look to see if there is a record of that install in the database and if there isn't it will go ahead and install a copy.

The config.xml version number is currently 0.1.0

The install script is currently

sql/namespace_modulename_setup/install-0.1.0.php

Have I misunderstood how Magento is installing tables or am I looking the wrong place or could it be a an error in the install script? if so how would I troubleshoot it?

===EDIT===

I thought I would add some of my code, as there must be an error in that, I am assuming that I have an error with my config due to the install file not even running so I have added that and an image of my filesenter image description here

<config>

<modules>
    <Mdg_Giftregistry>
        <version>0.1.0</version>
    </Mdg_Giftregistry>
</modules>

<global>
    <models>
        <mdg_giftregistry>
            <class>Mdg_Giftregistry_Model</class>
            <resourceModel>mdg_giftregistry_mysql4</resourceModel>
        </mdg_giftregistry>

        <mdg_giftregistry_mysql4>
            <class>Mdg_Giftregistry_Mysql4</class>
            <entities><!-- added on code review-->
                <entity>
                    <table>Mdg_Giftregistry_Entity</table>
                </entity>
                <item>
                    <table>Mdg_Giftregistry_Item</table>
                </item>
                <type>
                    <table>Mdg_Giftregistry_Type</table>
                </type>
            </entities><!-- added on code review-->
        </mdg_giftregistry_mysql4>

        <resources>
            <mdg_giftregistry_setup>
                <setup>
                    <module>Mdg_Giftregistry</module>
                    <class>Mdg_Giftregistry_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mdg_giftregistry_setup>

            <mdg_giftregistry_write>
                <use>core_write</use>
            </mdg_giftregistry_write>
            <mdg_giftregistry_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mdg_giftregistry_read>
        </resources>        
    </models>
.....
</config>

Best Answer

To add table to the database, use setup file in your module.

To insert a new table, please view this video

http://www.youtube.com/watch?v=M-LMInpT0ek

For Magento set up instructions , kindly check this http://alanstorm.com/magento_setup_resources

Related Topic