Magento supports creating, deleting, and updating database tables and fields in the module. In this way, adding and modifying fields becomes a very easy task in the process of plug-in development. Just modify the version number of the module and add a script that conforms to the naming convention in the file.
If the current Magento module is ruiwant_rewards and the version number is 0.9.0, we would like to add a status field for the integration table in this module. First step, we need to change the version number to 0.9.1. The data-upgrade-0.9.0-0.9.1.php file is then created in the root directory of the module (based on the directory you have been using, in this case, the data directory). Data/sql In the file, add the following code.
$installer = $ This; $table= $installergetconnection ()->addcolumn ($installer->gettable ('Rewards/point'),'Status', Varien_db_ddl_table::type_smallint,NULL, Array ('unsigned'=true, 'Nullable'=true, ), 'Point Status'); $installer->endsetup ();
If everything works, the table will successfully add a status field. Similar to AddColumn () more Magento Package database table structure modification method can refer to the article or directly to the source inside to see.
Magento Module Upgrade Modify database table structure