安装脚本出现'Magento错误':错误实体ID

4
我有以下的安装脚本,但是在运行时,我收到了Magento错误提示:
Error in file: "/vagrant/site.com/public_html/app/code/local/SS/Raptor/sql/raptor_setup/install-0.0.1.php" - Wrong entity ID

我的安装脚本如下:
$installer = new Mage_Eav_Model_Entity_Setup();
$installer->startSetup();

$installer->addAttribute('customer', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
));

$installer->addAttribute('quote', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
));

$installer->addAttribute('order', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
));

$installer->endSetup();

有什么想法为什么会发生这种情况吗?
3个回答

5
您正在使用错误的安装类。您可以使用Mage_Customer_Model_Entity_Setup以此方式添加属性。请参见此答案以使用Mage_Eav_Model_Entity_Setup添加客户属性。
其他报价属性需要不同的设置类。您可以在此处使用Mage_Sales_Model_Resource_Setup作为模型。

3

Magento2修复:

您需要在ModuleName/etc/module.xml文件中包含您的依赖项。我正在为产品添加自定义属性,必须包括以下内容:

<sequence>
    <module name="Magento_Catalog" />
</sequence>

嗨@sianguish,我解决了一个问题,但它又出现在Magento-Downloadable模块中,而我没有修改过。你有什么线索吗? - Cyberdelphos
1
请注意。我一次又一次地看到eav设置放置在install/upgradeSchema文件中。数据库的模式在这里没有改变,因此应该正确地放置在install/upgradeData脚本中。如果安装时遇到“错误的实体ID”的问题,原因是已经创建了Magento_Catalog的模式,但表中没有数据,这就是为什么会出现错误的原因。将代码放置在正确的升级脚本中可以解决此问题。 - DOfficial

0

由于您正在尝试为两个不同的实体创建属性,请在config.xml中使用以下代码:

    <config>
    <modules>
        <Namespace_Module>
            <version>0.1.1</version>
        </Namespace_Module>
    </modules>
---
---
<resources>
    <namespace_module_setup>
        <setup>
            <module>Namespace_Module</module>
            <class>Namespace_Module_Model_Resource_Setup</class>
        </setup>
    </namespace_module_setup>
</resources>

在 Setup.php 文件中编写以下代码。
class Namespace_Module_Model_Resource_Setup extends Mage_Customer_Model_Resource_Setup
{

}

然后创建两个独立的安装程序和升级文件。

install-0.1.0.php

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

$installer->addAttribute('customer', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
));

$installer->endSetup();

upgrade-0.1.0-0.1.1.php

$installer = $installer = new Mage_Sales_Model_Resource_Setup('core_setup');;

$installer->startSetup();

// now here write your code to create attribute 


$installer->endSetup();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接