1. 程式人生 > >Magento 更改已有模組的資料庫表的欄位資訊

Magento 更改已有模組的資料庫表的欄位資訊

比如要擴大模組對應的表的姓名一列的長度

1、首先增加指定模組的sql檔案,一般是模組名/sql/xxx_setup/upgrade_old_new.php old表示上一版本號,new代表本次版本號,new必須大於old,比如upgrade_1.0.0_1.1.0.php

2、編輯sql.php檔案

<?php
/**
$installer  = $this;
$installer->startSetup();
$installer->getConnection()->modifyColumn(   //modifyColumn代表修改列屬性
    $installer->getTable('customer_user_need_check
'), //模組對應的表名 'username', array( 'type' => Varien_Db_Ddl_Table::TYPE_TEXT,   'length' => '500', 'nullable' => false, 'default' => "", 'comment' => 'image url' ) ); $installer->endSetup();

3、到模組名/etc/config.xml檔案中設定模組版本號,即new

4、重新整理快取即可