0

I have been trying for three days to understand why I cant make this install script which I have run. I must have read every article on the subject at least twice and now feel I have a fairly sound knowledge on this part of Magento, but I still cannot get the code to run. The rest of the module works fine.

THE COMMON PROBLEMS IVE ALREADY ADDRESSED

Cache is disabled and I have manually flushed the cache(just in case). mdg_giftregistry_setup is not in the core_resource table in the database. The version number in my config file is the same as my install script. The node under resources is the same as the file in the sql folder.

I can see the install script is not even being hit by the browser, and I have no idea why. I have a nasty feeling that i've been staring at this problem so long that I cannot see a simple answer.

filepath

Mdg/Giftregistry/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>

    </models>

    <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>
            <connection>
                <use>core_write</use>
            </connection>
        </mdg_giftregistry_write>
        <mdg_giftregistry_read>
            <connection>
                <use>core_read</use>
            </connection>
        </mdg_giftregistry_read>
    </resources>         

    <blocks>
        <mdg_giftregistry>
            <class>Mdg_Giftregistry_Block</class>
        </mdg_giftregistry>
    </blocks>

    <helpers>
        <mdg_giftregistry>
            <class>Mdg_Giftregistry_Helper</class>
        </mdg_giftregistry>
    </helpers>


</global>

<frontend>
    <routers>
        <mdg_giftregistry>
            <use>standard</use>
            <args>
                <module>Mdg_Giftregistry</module>
                <frontName>giftregistry</frontName>
            </args>
        </mdg_giftregistry>
    </routers>
</frontend>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <mdg_giftregistry before="Mage_Adminhtml">Mdg_Giftregistry_Adminhtml</mdg_giftregistry>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

<adminhtml>
    <!--NON BOOK CODE-->
    <!--Adds menu item to menu bar-->
    <menu>
        <giftregistry translate="title" module="mdg_giftregistry">
            <title>Giftregistrys</title><!--menu item title-->
            <sort_order>100</sort_order><!--menu item locaiton-->
            <children>
                <index translate="title" module="mdg_giftregistry">
                    <title>index</title><!--menus sub item title-->
                    <sort_order>1</sort_order><!--sub item order-->
                    <action>adminhtml/giftregistry/index</action><!--destination-->
                </index>
                <save translate="title" module="mdg_giftregistry">
                    <title>save</title><!--menus sub item title-->
                    <sort_order>2</sort_order><!--sub item order-->
                    <action>adminhtml/giftregistry/save</action><!--destination-->
                </save>
                <new translate="title" module="mdg_giftregistry">
                    <title>new</title><!--menus sub item title-->
                    <sort_order>3</sort_order><!--sub item order-->
                    <action>adminhtml/giftregistry/new</action><!--destination-->
                </new>
                <delete translate="title" module="mdg_giftregistry">
                    <title>mass delete</title><!--menus sub item title-->
                    <sort_order>4</sort_order><!--sub item order-->
                    <action>adminhtml/giftregistry/massDelete</action><!--destination-->
                </delete>
            </children>
        </giftregistry>
    </menu>
    <!--NON BOOK CODE-->

    <layout>
        <updates>
            <mdg_giftregistry module="mdg_giftregistry">
                <file>giftregistry.xml</file>
            </mdg_giftregistry>
        </updates>
    </layout>
</adminhtml>

Mdg/Giftregistry/sql/mdg_giftregistry_setup/install-0.1.0.php

<?php

$installer = $this;

$installer->startSetup();
//Create the mdg_giftregistry/registry table
$tableName = $installer->getTable('mdg_giftregistry/entity');
//check if the table already exists

if ($installer->getConnection() ->isTableExists($tableName) != TRUE) {
   $table = $installer->getConnection()
       ->newTable($tableName)
       ->addColumn('entity_id',
                    Varien_Db_Ddl_Table::TYPE_INTEGER,
                    null,
                    array(
                        'identity' => TRUE,
                        'unsigned' => TRUE,
                        'nullable' => FALSE,
                        'primary' => TRUE,
                    ),
                    'Entity Id'
                  )
       ->addColumn('customer_id',
                    Varien_Db_Ddl_Table::TYPE_INTEGER,
                    null,
                    array(
                        'unsigned' => TRUE,
                        'nullable' => FALSE,
                        'default' => '0',
                    ),
                    'Customer Id'
                  )
       ->addColumn('type_id',
                   Varien_db_Ddl_Table::TYPE_SMALLINT,
                   NULL,
                   array(
                       'unsigned' => TRUE,
                       'nullable' => FALSE,
                       'default' => '0',
                   ),
                   'Type Id'
                  )
       ->addColumn('website_id',
                   Varien_db_Ddl_Table::TYPE_SMALLINT,
                   NULL,
                   array(
                       'unsigned' => TRUE,
                       'nullable' => FALSE,
                       'default' => '0',
                   ),
                   'Website Id'
                  )
       ->addColumn('event_name',
                   VARIEN_DB_Ddl_Table::TYPE_TEXT,
                   255,
                   array(),
                   'Event Name'
                  )
       ->addColumn('event_date',
                   VARIEN_DB_Ddl_Table::TYPE_DATE,
                   NULL,
                   array(),
                   'Event Date'
                  )
       ->addColumn('event_country',
                   VARIEN_DB_Ddl_Table::TYPE_TEXT,
                   3,
                   array(),
                   'Event Country'
                  )
       ->addColumn('event_location',
                   VARIEN_DB_Ddl_Table::TYPE_TEXT,
                   255,
                   array(),
                   'Event Location'
                  )
       ->addColumn('created_at',
                   VARIEN_DB_Ddl_Table::TYPE_TIMESTAMP,
                   NULL,
                   array(
                       'nullable' => FALSE
                   ),
                   'Created At'
                  )
        ->addIndex($installer->getIdxName('mdg_giftregistry/entity',
                                          array('customer_id')
                                         ),
                   array('customer_id')                    
                  )
        ->addIndex($installer->getIdxName('mdg_giftregistry/entity',
                                          array('website_id')
                                         ),
                   array('website_id')                    
                  )
        ->addIndex($installer->getIdxName('mdg_giftregistry/entity',
                                          array('type_id')
                                         ),
                   array('type_id')                    
                  )

        ->addForeignKey($installer->getFkName(
                        'mdg_giftregistry/entity',
                        'website_id',
                        'core/website',
                        'website_id'
                        ),
                        'website_id', $installer->getTable('core/website'),
                        'website_id',
                         Varien_Db_Ddl_Table::ACTION_CASCADE
                  )
        ->addForeignKey($installer->getFkName(
                        'mdg_giftregistry/entity',
                        'website_id',
                        'core/website',
                        'website_id'
                        ),
                        'website_id', $installer->getTable('core/website'),
                        'website_id',
                        Varien_Db_Ddl_Table::ACTION_CASCADE,     Varien_Db_Ddl_Table::ACTION_CASCADE
                  )
        ->addForeignKey($installer->getFkName(
                        'mdg_giftregistry/entity',
                        'type_id',
                        'core/website',
                        'type_id'
                        ),
                        'type_id',
                        $installer->getTable('mdg_giftregistry/type'),
                        'type_id',
                        Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE                      
                  );
        $installer->getConnection()->createTable($table);
}


$installer->endSetup();

setup.php extends Mage_Core_Model_Resource_Setup (if that makes a difference)

  • 1
    I highly recommend to use magicento.com (PHPStorm Plugin) to avoid these types of mistakes. – Fabian Blechschmidt Sep 5 '13 at 15:33
2

The <resources> tag must be outside the <models> tag. They should be siblings, not parent and child. <resources> should be a child of <global>.

|improve this answer|||||
  • Obviously I didn't read those articles well enough. It is now in core resource table, but the tables have not show up in the database – tony09uk Sep 5 '13 at 14:38
  • @tony09uk add the install script to the question. Also the full config.xml file could help. – Marius Sep 5 '13 at 14:44
  • My post has been updated – tony09uk Sep 5 '13 at 14:57
  • @tony09uk. I;ve tested with your code and the table was created. I only added the file in app/etc/module and the Setup class that just extends the core Setup class. Make sure you are looking in the right database :). You can try to re-install. Delete the record corresponding to your module from core_resource and refresh any page – Marius Sep 5 '13 at 15:07
  • Thankyou for testing that, Im definatly looking in the right db and have searched for mdg_giftregistry_entity but there is no table of that name. Thanks for you help I will keep looking, unless you have any other suggestions? – tony09uk Sep 5 '13 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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