Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Setup Sql Files are not going to run any more.. Please Help Regarding This. 
 
Vaibhav Soni
Jr. Member
 
Total Posts:  25
Joined:  2011-01-31
 

Hello All,

Setup SQL Files are not going to run any more. I am talking about the sql/moule_setup/ folder files. Can anyone please tell me from where i should start debugging..?

If I put same module to any default magento , It runs successfully. I am using magento1.6.0.0.

Please Help..

Regards,
Vaibhav Munjpara.

 
Magento Community Magento Community
Magento Community
Magento Community
 
niro
Mentor
 
Avatar
Total Posts:  1609
Joined:  2009-03-04
Latvia, Riga
 

Magento stores information about installed moduels in data base table core_resource.
If module is marked as installed - setup will not be executed any more. IF you need to run it one more time: delete information about extension from this table.

 
Magento Community Magento Community
Magento Community
Magento Community
 
SarathTomy
Sr. Member
 
Avatar
Total Posts:  146
Joined:  2009-03-13
Melbourne, Australia
 

Hi Vaibhav ,

An easy solution is to delete the record which contains the specified module name from the \’core_resource\’ table.

The Functionality is explanation is :

1. Actuallly the sql file that we created for a module is executed when any magento page is opened in the browser.

2. The database ‘core_resource’ maintains the module version and name of each module loaded into magento.

3. Magento checks the module version in database and the module version specified in the config.xml file in our module etc folder.

4. If the version in config.xml greater than database version, it executes the corresponding sql file and update the module version in database.Otherwise it won’t execute again.

In your case, the version is already get inserted. Since you won’t made any change in the versioning. So it won’t get executed.

If you have time this is the detailed explanation from my knowledge.

When we create a new module, In your app/etc/local/Company/Testmodule/etc/config.xml

<config>
    <
modules>
        <
Company_Testmodule>
            <
version>0.1.0</version>
        </ 
Company _Testmodule>
    </
modules>

Here the version declared inside the <version> tag of our module is 0.1.0

In your app/etc/local/Company/Testmodule/sql/testmodule_setup/, you can find the file mysql4-install-0.1.0.php

And in that file, there we can see the module setup

$installer $this;

$installer->startSetup();

$installer->run(\"

-- DROP TABLE IF EXISTS {
$this->getTable(\'testmodule\')};
CREATE TABLE {
$this->getTable(\'testmodule\')} (
  `testmodule_id` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default \'\',
  `filename` varchar(255) NOT NULL default \'\',
  `content` text NOT NULL default \'\',
  `status` smallint(6) NOT NULL default \'0\',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`testmodule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    \"
);

$installer->endSetup();

Have a look at the version mentioned in the configuration file and the name of the installer file. Both are same na. In the ‘core_resource’ table also you can find the module with the same version 0.1.0. So it wont get executed again, even if you made changes in the sql file.

So the easy way (not the correct way) to execute it again is to remove the record from the ‘core_resource’ table.

But the correct way is to upgrade the version. In order to upgrade the version,

1. Increase the version number in the app/etc/local/Company/Testmodule/etc/config.xml

For example,

<config>
    <
modules>
        <
Company_Testmodule>
            <
version>0.1.1</version>
        </ 
Company _Testmodule>
    </
modules>

2.Then create a new sql file named mysql4-upgrade-0.1.0-0.1.1.php inside the folder app/etc/local/Company/Testmodule/sql/testmodule_setup/

3. Inside that file we can write the changes needed for the table when upgrading the version.

$this->run(\"

alter table {
$this->getTable(\'testmodule\')} add column `test` tinyint (1)UNSIGNED  DEFAULT \'1\' NOT NULL  after `status`;

\"
);

Since the version in the configuration file is higher than the version in the core_resource table, it get executed successfully and updated the table with the new version.

If we look into the folder app\\code\\core\\Mage\\Catalog\\sql\\catalog_setup\\ , we can see many upgradations.Please check these for reference.

Hope it helps....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vaibhav Soni
Jr. Member
 
Total Posts:  25
Joined:  2011-01-31
 
SarathTomy - 06 March 2012 09:45 PM

Hi Vaibhav ,

An easy solution is to delete the record which contains the specified module name from the \’core_resource\’ table.

The Functionality is explanation is :

1. Actuallly the sql file that we created for a module is executed when any magento page is opened in the browser.

2. The database ‘core_resource’ maintains the module version and name of each module loaded into magento.

3. Magento checks the module version in database and the module version specified in the config.xml file in our module etc folder.

4. If the version in config.xml greater than database version, it executes the corresponding sql file and update the module version in database.Otherwise it won’t execute again.

In your case, the version is already get inserted. Since you won’t made any change in the versioning. So it won’t get executed.

If you have time this is the detailed explanation from my knowledge.

When we create a new module, In your app/etc/local/Company/Testmodule/etc/config.xml

<config>
    <
modules>
        <
Company_Testmodule>
            <
version>0.1.0</version>
        </ 
Company _Testmodule>
    </
modules>

Here the version declared inside the <version> tag of our module is 0.1.0

In your app/etc/local/Company/Testmodule/sql/testmodule_setup/, you can find the file mysql4-install-0.1.0.php

And in that file, there we can see the module setup

$installer $this;

$installer->startSetup();

$installer->run(\"

-- DROP TABLE IF EXISTS {
$this->getTable(\'testmodule\')};
CREATE TABLE {
$this->getTable(\'testmodule\')} (
  `testmodule_id` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default \'\',
  `filename` varchar(255) NOT NULL default \'\',
  `content` text NOT NULL default \'\',
  `status` smallint(6) NOT NULL default \'0\',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`testmodule_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    \"
);

$installer->endSetup();

Have a look at the version mentioned in the configuration file and the name of the installer file. Both are same na. In the ‘core_resource’ table also you can find the module with the same version 0.1.0. So it wont get executed again, even if you made changes in the sql file.

So the easy way (not the correct way) to execute it again is to remove the record from the ‘core_resource’ table.

But the correct way is to upgrade the version. In order to upgrade the version,

1. Increase the version number in the app/etc/local/Company/Testmodule/etc/config.xml

For example,

<config>
    <
modules>
        <
Company_Testmodule>
            <
version>0.1.1</version>
        </ 
Company _Testmodule>
    </
modules>

2.Then create a new sql file named mysql4-upgrade-0.1.0-0.1.1.php inside the folder app/etc/local/Company/Testmodule/sql/testmodule_setup/

3. Inside that file we can write the changes needed for the table when upgrading the version.

$this->run(\"

alter table {
$this->getTable(\'testmodule\')} add column `test` tinyint (1)UNSIGNED  DEFAULT \'1\' NOT NULL  after `status`;

\"
);

Since the version in the configuration file is higher than the version in the core_resource table, it get executed successfully and updated the table with the new version.

If we look into the folder app\\code\\core\\Mage\\Catalog\\sql\\catalog_setup\\ , we can see many upgradations.Please check these for reference.

Hope it helps....

Hi, SarathTomy,

I have tried like above. I have a fresh module , i mean there are no any entries in core_resource table for my module in project.

If i install it in default magento, then it runs succefully.All Sql setup files(install and upgrade) run successfully and also one entry is created in core_resource table.

But in a project for which i want to install it, set up sql files are not being run. And core_resource table entry is also not being created.  Can you please help me from where i should start debugging..?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vaibhav Soni
Jr. Member
 
Total Posts:  25
Joined:  2011-01-31
 

This issue is still not resolved. To trace this issue more, can anyone know me when(I mean from which file) sql setup files are called and how one by one module is called and from where.. ?

Thanks.
Regards,
Vaibhav Munjjpara.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top