【问题标题】:Installer Script gives me 'Wrong Entity ID' Magento error安装程序脚本给了我“错误的实体 ID”Magento 错误
【发布时间】:2014-05-13 14:06:20
【问题描述】:

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

任何想法为什么会发生这种情况?

【问题讨论】:

    标签: magento magento-1.7


    【解决方案1】:

    您使用了错误的设置类。您可以使用Mage_Customer_Model_Entity_Setup 以这种方式添加属性。请参阅use Mage_Eav_Model_Entity_Setup to add customer attributes 的回复。

    其他报价属性需要不同的设置类。您可以在这里使用Mage_Sales_Model_Resource_Setup 作为模型。

    【讨论】:

      【解决方案2】:

      Magento2 修复:

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

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

      【讨论】:

      • 嗨@sianguish,我解决了一个问题,但后来它再次出现在我没有修改的Magento-Downloadable模块中。你有什么线索吗?
      • 请注意。我一次又一次地看到安装/升级架构文件中的 eav 设置。数据库的模式在这里没有改变,因此应该正确地放置在 install/upgradeData 脚本中。您在安装时遇到“错误的实体 ID”的问题是 Magento_Catalog 的架构已创建,但表中没有数据,这就是您收到错误的原因。将您的代码放在正确的升级脚本中可以解决这个问题。
      【解决方案3】:

      当您尝试为两个不同的实体创建属性时,请在 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
      {
      
      }
      

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-16
        • 1970-01-01
        • 2019-09-04
        相关资源
        最近更新 更多