Magento 安装程序脚本为我提供了';错误的实体ID';马根托误差

Magento 安装程序脚本为我提供了';错误的实体ID';马根托误差,magento,magento-1.7,Magento,Magento 1.7,我有以下安装程序脚本-当我尝试运行此脚本时,会出现以下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->startSetu

我有以下安装程序脚本-当我尝试运行此脚本时,会出现以下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();

知道为什么会发生这种情况吗?

您使用了错误的设置类。您可以使用
Mage\u Customer\u Model\u Entity\u Setup
以这种方式添加属性。看看这个答案

其他报价属性需要不同的设置类。您可以在此处使用
Mage\u Sales\u Model\u Resource\u Setup
作为模型。

Magento2修复:

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

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

当您试图为两个不同的实体创建属性时,请在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>
然后创建两个单独的安装程序和升级文件

安装-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();
升级至-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();

您好@sianguish,我解决了一个问题,但是它再次出现在Magento可下载模块中,我没有修改它。你有什么线索吗?只要记下来。我一次又一次地看到eav安装程序放在安装/升级模式文件中。数据库的架构在此没有更改,因此应正确地放置在安装/升级数据脚本中。安装时遇到“错误实体ID”的原因是,Magento_目录的架构已创建,但表中没有数据,因此会出现错误。将代码放在适当的升级脚本中可以解决此问题。
$installer = $installer = new Mage_Sales_Model_Resource_Setup('core_setup');;

$installer->startSetup();

// now here write your code to create attribute 


$installer->endSetup();