2016-09-25 6 views
1

Magentoを新しくしました。私は、configファイルの更新magento既存のテーブルに列を追加する

<?php 
$installer = $this; 
$installer->startSetup(); 
$installer->getConnection()->addColumn(
    $this->getTable('newsletter/subscriber'), //table name 
    'groupid',        //column name 
    'varchar(100) NOT NULL'     //datatype definition 
); 

$installer->endSetup(); 

?> 

app/code/core/mage/newsletter_setup/に新しいファイルmysql4-upgrade-1.6.0.0-1.6.0.1.phpを作ったので、私はnewsletter_subscriberテーブルの列を追加したい:それは動作しません

<modules> 
    <Mage_Newsletter> 
     <version>1.6.0.0</version> 
    </Mage_Newsletter> 
</modules> 

を、私は何を案内してください間違っている

答えて

5

コアファイルの追加/変更や変更はお勧めしません。新しいモジュールを作成して余分な列を追加する方が良いでしょう。

app/code/local/your/module/sql/your_module_setup/upgrade-0.1.2-0.1.3.phpファイルでモジュールのアップグレードに正しいバージョンが必要です。 (つまり、モジュールのバージョンを0.1.2から0.1.3にアップグレードすることを意味します)。あなたがアップグレードスクリプトを使用していない場合は、モジュール​​3210で<resources>を定義するために覚えていると、セットアップスクリプト名は以下mysql4-install-0.1.0.php

であることはMySQLのセットアップスクリプトファイルです -

<?php 
     ini_set('display_errors', '1'); 

     $installer = $this; 
     $installer->startSetup(); 
     $installer->getConnection() 
       ->addColumn(
        $installer->getTable('newsletter/subscriber'), //Get the newsletter Table 
        'your_field_name', //New Field Name 
      array(
       'type'  => Varien_Db_Ddl_Table::TYPE_TEXT, //Field Type like TYPE_INTEGER ... 
       'nullable' => true, 
       'length' => 255, 
       'default' => 'Some thing default value', 
       'comment' => 'Your field comment' 
      ) 
     );    
     $installer->endSetup(); 
     ?> 

とその変化アプリ/コード/ローカル後upgrade-0.1.2-0.1.3.php /your/module/etc/config.xmlバージョンたとえば、

<config> 
    <modules> 
     <NameSpace_ModuleName> 
      <version>0.1.3</version> <!-- if upgrade script version is 0.1.3 --> 
     </NameSpace_ModuleName> 
    </modules> 
    <global> 
    <resources> 
     <NameSpace_ModuleName_setup> 
      <setup> 
       <module>NameSpace_ModuleName</module> 
       <class>Mage_Catalog_Model_Resource_Setup</class> 
      </setup> 
      <connection> 
       <use>core_setup</use> 
      </connection> 
     </NameSpace_ModuleName_setup> 
     </resources> 
    </global> 
</config> 
2

セットアップスクリプトでは、モジュールのバージョンの変更に従って実行されます。あなたのケースでは

バージョンが1.6.0.0ている間、あなたのファイル名は、mysql4-upgrade-1.6.0.0-1.6.0.1.phpです。この特定のスクリプトを実行させるには、バージョンを1.6.0.1にバンプする必要があります。

これは、悪い習慣であるMagentoのコアモジュールに機能を追加するというものです。代わりにこれをローカルプール(app/code/local)モジュールに移動する必要があります。

関連する問題