magento 将自定义列添加到 eav_attribute table

magento adding custom column to eav_attribute table

我想将我的自定义字段(数据库中的列)添加到 table eav_attribute 这是我在 t

中的配置模型和资源
 <models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <module>Mage_Eav</module>
        <module>Mage_Eav_Model_Entity_Setup</module>
    </mycompany_filters_setup>
</resources>

目录树


sql
 -- mycompany_filters_setup
  -- install-0.1.4.php

和内容文件 install-0.1.4.php


<?php

$installer = $this;
/* @var $installer Mage_Eav_Model_Entity_Setup */

$installer->startSetup();

$installer->getConnection()->addColumn(
    $installer->getTable('eav/attribute'), 
    "is_used_in_category", 
    "TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0'"
);

$installer->endSetup();

但这不起作用。在 table core_resource 中不为 mycompany_filters 创建字符串资源并且在 table eav_attribute 中不创建新列。

错误日志:system.log 和 exception.log apache2 日志为空

主要问题为什么不起作用?

我想在这里指出一些我认为错误的地方。

首先你的 config.xml:

<models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <module>Mage_Eav</module>
        <module>Mage_Eav_Model_Entity_Setup</module>
    </mycompany_filters_setup>
</resources>

应该是:

<models>
    <mycompany_filters>
        <class>Mycompany_Filters_Model</class>
        <resourceModel>mycompany_filters_resource</resourceModel>
    </mycompany_filters>
    <mycompany_filters_resource>
        <class>Mycompany_Filters_Model_Resource</class>
    </mycompany_filters_resource>
</models>
<resources>
    <mycompany_filters_setup>
        <setup>
            <module>Mage_Eav</module>
            <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <!-- You could add these as well
        <connection>
            <use>core_setup</use>
        </connection>
        -->
    </mycompany_filters_setup>
    <!-- If you add the connection tag above, you should add these as well
    <filters_write>
        <connection>
            <use>core_write</use>
        </connection>
    </filters_write>
    <filters_read>
        <connection>
            <use>core_read</use>
        </connection>
    </filters_read>
    -->
</resources>

本质上,您缺少应该包装资源 <module><class> 标签的 <setup> 标签。

install-0.1.4.php 的内容应该改为:

$installer = $this;
$installer->startSetup();

$table = $installer->getTable('eav/attribute');
$installer->getConnection()
        ->addColumn($table, 'is_used_in_category', array(
            'type'      => 'could be Varien_Db_Ddl_Table::TYPE_TEXT or any you want it should be',
            'nullable'  => true, //could be true or false
            'default'   => null, //default value for this attribute
            'unique'    => true, //could be true or false
            'comment'   => 'Your comment here. Not important'
        ));

$installer->endSetup();

在您的 config.xml 中,确保声明的版本与 0.1.4 相同。 在这些更改和运行您的应用程序后清除您的缓存。

希望对您有所帮助。