0

I have created a category attribute is_personalizable.

Below is mysql4-install-0.0.1.php

<?php
$installer = $this;
$installer->startSetup();
$attribute  = array(
    'type'          =>  'text',
    'label'         =>  'Is Personalizable>',
    'input'         =>  'select',
    'global'        =>  Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible'       =>  true,
    'required'      =>  false,
    'user_defined'  =>  true,
    'default'       =>  "0",
    'group'         =>  "General Information",
    'option'        => array(
                            'value' => array(
                                '0' => 'No',
                                '1' => 'Yes',
                            )
                        ),
);
$installer->addAttribute('catalog_category', 'is_personalizable', $attribute);
$installer->endSetup();
?>

Unfortunately I did a mistake on the label field. So I try to update the attribute. Below is my mysql4-install-0.0.2.php

<?php
$installer = $this;
$installer->startSetup();

$installer->updateAttribute('catalog_category','is_personalizable','label', 'Is Personalizable?');

$installer->endSetup();
?>

But the change is not reflecting, I am not sure whether the file is being executed or not?

Below are the questions:

1. Whats the mistake on the update?
2. Creating and updating attribute will have to sql version .php files, so when I migrate from one server to another how magento will
know the version 1 and 2 so on.
3. How to know whether my update query executed or not?

Please advise.

3

You need to rename the file mysql4-install-0.0.2.php to mysql4-upgrade-0.0.1-0.0.2.php and change in config.xml the <version> tag value from 0.0.1 to 0.0.2.
And clear the cache.
if you already changed the version in your config.xml and refreshed a page then the module will be considered at version 0.0.2 and your script will not be triggered.
So instead of naming it mysql4-upgrade-0.0.1-0.0.2.php name it mysql4-upgrade-0.0.2-0.0.3.phpand change the version to 0.0.3 in config.xml.

  • So my file name should be mysql4-upgrade-0.0.1-0.0.2.php and if i have next update file should be mysql4-upgrade-0.0.2-0.0.3.php and so on.. Am i right ? – Butterfly Jun 11 '15 at 13:50
  • @new_bee_magento. You got it. – Marius Jun 11 '15 at 13:51
  • If you dont mind, There are some extension I can see setup file as mysql4-upgrade-0.1.0.php so next version should be mysql4-upgrade-0.1.0-0.2.0.php ... and in config <version>0.2.0</version> am I right? – Butterfly Jun 11 '15 at 13:53
  • 1
    if by "I can see setup file as mysql4-upgrade-0.1.0.php" you mean "I can see setup file as mysql4-install-0.1.0.php" you are kind of right. Ne next version can be 0.2.0 but it can also be 0.1.1, or 1.0.0. Magento uses version_compare to compare the version numbers. See how that works. If you actually saw extensions that have the file mysql4-upgrade-0.1.0.php then there is something wrong. that's not a valid upgrade script. – Marius Jun 11 '15 at 14:05
  • At present files inside sql/custom_attribute_setup are mysql4-install-0.0.1.php and mysql4-upgrade-0.0.1-0.0.2.php. I changed version in Ucs\CategoryAttribute\etc\config.xml as <version>0.0.2</version>. But unluckily attribute not updated, can you please help me ? – Butterfly Jun 13 '15 at 7:17
1

the update script name is wrong.It should be mysql4-upgrade--0.0.1-0.0.2.php from mysql4-install-0.0.2.php.

Also need to check this version at config.xml

<version>0.0.2</version

As per as magento system for first time install script should be mysql4-install-VersionNO.php after that all update file name should like this

mysql4-Upgrade-OldversionNo-VersionNO.php
  • assume I have four updates initial sql setup file is mysql4-install-0.0.1.php then what would be the remaining file names? Is there any sequence I should follow? – Butterfly Jun 11 '15 at 13:45
  • If I add a Mage::log('Query Executed', null, 'setup.log'); in my upgrade setup file will it work? – Butterfly Jun 11 '15 at 14:05
  • there was a mistake on my answer, and i have update ot .plz follow @marius answer for better knowledge – Amit Bera Jun 11 '15 at 14:07
1

FYI - To check the current version of your module that Magento has executed, check the core_resources table. Find your module and cross-check the current version. If it is indeed your latest version and your changes aren't appearing as desired, then there may be an error with the actual query you're trying to run... If the version is the old one then it could indicate that you perhaps haven't:

  • Named the upgrade file correctly (should be upgrade-oldversion-newversion.php)
  • Changed your modules config.xml file so that the version number within the <version></version> tags reflect your new version number.
1

Alternatively, if you're developing and don't want to keep incrementing version numbers, simply delete the module row within the core_resources table.

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.