0

I get some trouble in auto create table for model . I create module 'rewardpoint' by moduleCreator and it generate rewardpoint model automatically,But i want to create new Model 'rate' in my module . So , this is my code :

-config.xml

<models>
        <rate>
            <class>Magestore_Rewardpoint_Model</class>
            <resourceModel>rate_mysql4</resourceModel>
        </rate>
        <rate_mysql4>
            <class>Magestore_Rewardpoint_Model_Mysql4</class>
            <entities>
                <rate>
                    <table>rewardpoints_rate</table>
                </rate>
            </entities>
        </rate_mysql4>
    </models>
<resources>
        <rewardpoint_setup>
            <setup>
                <module>Magestore_Rewardpoint</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </rewardpoint_setup>
        <rewardpoint_write>
            <connection>
                <use>core_write</use>
            </connection>
        </rewardpoint_write>
        <rewardpoint_read>
            <connection>
                <use>core_read</use>
            </connection>
        </rewardpoint_read>
   </resources>

And in sql folder , i change code too

$installer = $this;

$installer->startSetup();

/**
 * create rewardpoint table
 */
$installer->run("

DROP TABLE IF EXISTS {$this->getTable('rewardpoints_rate')};

CREATE TABLE {$this->getTable('rewardpoints_rate')} (
  `rate_id` int(11) unsigned NOT NULL auto_increment,
  `direction` smallint(6) NOT NULL,
  `point` int(11) NOT NULL,
  `money` int(11) NOT NULL,
  `customer_group` varchar(20) NOT NULL ,
  PRIMARY KEY (`rate_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

");

Then i refesh browser and see my phpadmin result , there's no table name 'rewardpoints_rate'.

1

3 Answers 3

1

I would like to add this as a comment, but then it is unreadable.

You don't need all the XML nodes, because magento adds them automatically:

<resources>
    <rewardpoint_setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </rewardpoint_setup>
    <rewardpoint_write>
        <connection>
            <use>core_write</use>
        </connection>
    </rewardpoint_write>
    <rewardpoint_read>
        <connection>
            <use>core_read</use>
        </connection>
    </rewardpoint_read>

You can remove them if you want.

0
0

For run sql_setup you need define resource

<resources>
    <rate_setup>
    <setup>
        <module>Magestore_Rewardpoint</module>
    </setup>
    <connection>
        <use>core_setup</use>
    </connection>
    </rate_setup>
    <rate_read>
    <connection>
        <use>core_read</use>
    </connection>
    </rate_read>
    <rate_write>
    <connection>
        <use>core_write</use>
    </connection>
    </rate_write>
</resources>
1
  • i fixed it , its because this module has run before . so i have to delete its cache from core_resource . thank you
    – freeman167
    Oct 6, 2014 at 3:13
0

Also try this

<?xml version="1.0"?>
<config>
  <modules>
    <Magestore_Rewardpoint>
      <version>0.1.0</version>
    </Magestore_Rewardpoint>
  </modules>
  <global>
    <helpers>
      <rewardpoint>
         <class>Magestore_Rewardpoint_Helper</class>
      </rewardpoint>
    </helpers>
    <resources>
      <rewardpoint_setup>
        <setup>
          <module>Magestore_Rewardpoint</module>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </rewardpoint_setup>
      <rewardpoint_write>
        <connection>
          <use>core_write</use>
        </connection>
      </rewardpoint_write>
      <rewardpoint_read>
        <connection>
          <use>core_read</use>
        </connection>
      </rewardpoint_read>
    </resources>
  </global>
</config> 

Also try this code for app\code\local\Magestore\Rewardpoint\sql\rewardpoint_setup\mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$sql=<<<SQLTEXT
create table rewardpoints_rate('rate_id' int(11) unsigned NOT NULL auto_increment, 'direction' smallint(6) NOT NULL,'point` int(11) NOT NULL,'money' int(11) NOT NULL, 'customer_group' varchar(20) NOT NULL , PRIMARY KEY ('rate_id'));
SQLTEXT;

$installer->run($sql);

$installer->endSetup();

Hope this will work for you

1
  • i fixed it , its because this module has run before . so i have to delete its cache from core_resource . thank you
    – freeman167
    Oct 6, 2014 at 3:14

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.