1

Here is my config and Model classes.

I have changed the version number in both the config and sql installer.

But still the custom table doesnt seem to be added in core_resource table.

Where am i wrong?

 <config>
 <modules>
    <Vendor_Recipe>
        <version>1.0.1</version>
    </Vendor_Recipe>
</modules>
<global>
     <resources>
        <vendor_recipe_setup>
            <setup>
                <module>Vendor_Recipe</module>
                <class>vendor_Recipe_Model_Resource_Setup</class>
            </setup>
        </vendor_recipe_setup>
    </resources>

    <models>
        <vendor_recipe>
            <class>Vendor_Recipe_Model</class>
            <resourceModel>vendor_recipe_resource</resourceModel>
        </vendor_recipe>

        <vendor_recipe_resource>
            <class>Vendor_Recipe_Model_Resource</class>
            <entities>
                   <spen_recipe>    
                        <table>spen_recipe</table>
                    </spen_recipe>
             </entities>
        </vendor_recipe_resource>

     </models>
   </global>
    ....

Vendor\Recipe\sql\vendor_recipe_setup\install-1.0.1.php

<?php

 $installer = $this;

 $installer->startSetup();

 $table = $installer->getConnection()
->newTable($installer->getTable('vendor_recipe/spen_recipe'))
->addColumn('vendor_recipe/recipe_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'identity'  => true,
    'unsigned'  => true,
    'nullable'  => false,
    'primary'   => true,
    ), 'Recipe ID')
->addColumn('vendor_recipe/user_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
    'nullable'  => false,
    ), 'USer ID');
$installer->getConnection()->createTable($table);

vendor\Recipe\Model\SpenRecipe.php

<?php
class vendor_Recipe_Model_SpenRecipe extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {
        $this->_init('vendor_recipe/spen_recipe');
    }
}

\Recipe\Model\Resource\SpenRecipe.php

<?php

class vendor_Recipe_Model_Resource_SpenRecipe extends Mage_Core_Model_Resource_Db_Abstract
 {
   protected function _construct()
  {
    $this->_init('vendor_recipe/spen_recipe', 'recipe_id');
  }
}

\Recipe\Model\Resource\SpenRecipe\Collection.php

<?php
class vendor_Recipe_Model_Resource_SpenRecipe_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
    public function _construct()
    {
        $this->_init('vendor_recipe/spen_recipe');
    }
}

1 Answer 1

0

@QaisarSatti mysql keyword is necessary but for magento 1.8 or previous version. from magento1.9 onwards you can create setup class or you can use default setup class. and you dont have to write mysql before your script filename

for that you have to change your resource node like below .

<resources>
    <vendor_recipe_setup>
        <setup>
            <module>Vendor_Recipe</module>
            <class>Mage_Core_Model_Resource_Setup</class> <!--or your  setup class -->    
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </vendor_recipe_setup>
    <vendor_recipe_write>
        <connection>
            <use>core_write</use>
        </connection>
    </vendor_recipe_write>
    <vendor_recipe_read>
        <connection>
            <use>core_read</use>
        </connection>
    </vendor_recipe_read>
</resources>

or you can create your own setup class and extend this core class to this and provide your own class to resource setup node

<?php 
class Vendor_Recipe_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup
{  

}
?>

And also there is a mistake in your

Recipe\Model\Resource\SpenRecipe\Collection.php file

class name should be

   `Vendor_Recipe_Model_Resource_SpenRecipe_Collection`

instead

  `vendor_Recipe_Model_Resource_SpenRecipe_Collection`

and your folder name to should be Vendor not vendor

and also Recipe\Model\Resource\SpenRecipe.php

class name should be

`class Vendor_Recipe_Model_Resource_SpenRecipe`

not class vendor_Recipe_Model_Resource_SpenRecipe

and also Vendor\Recipe\Model\SpenRecipe.php file

class name should be class Vendor_Recipe_Model_SpenRecipe not class vendor_Recipe_Model_SpenRecipe

And also change your config.xml accordingly

     <config>
 <modules>
    <Vendor_Recipe>
        <version>1.0.1</version>
    </Vendor_Recipe>
</modules>
<global>
     <resources>
        <vendor_recipe_setup>
            <setup>
                <module>Vendor_Recipe</module>
                <class>Vendor_Recipe_Model_Resource_Setup</class> <!-- V change -->
            </setup>
        </vendor_recipe_setup>
    </resources>

    <models>
        <vendor_recipe>
            <class>Vendor_Recipe_Model</class>
            <resourceModel>vendor_recipe_resource</resourceModel>
        </vendor_recipe>

        <vendor_recipe_resource>
            <class>Vendor_Recipe_Model_Resource</class>
            <entities>
                   <spen_recipe>    
                        <table>spen_recipe</table>
                    </spen_recipe>
             </entities>
        </vendor_recipe_resource>

     </models>
   </global>
1
  • change in layout by adding <connection> worked, thanks
    – Sushivam
    Nov 3, 2016 at 10:38

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.