我有以下安装程序脚本 - 当我尝试运行此脚本时,我收到以下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();
为什么会发生这种情况的任何想法?
答案 0 :(得分:3)
您使用的是错误的安装类。您可以使用Mage_Customer_Model_Entity_Setup
以这种方式添加属性。请参阅use Mage_Eav_Model_Entity_Setup to add customer attributes的答案。
其他引用属性需要不同的安装类。您可以在此处使用Mage_Sales_Model_Resource_Setup
作为模型。
答案 1 :(得分:3)
Magento2修复:
您需要在ModuleName / etc / module.xml文件中包含依赖项。我正在为Products添加自定义属性,并且必须包括:
<sequence>
<module name="Magento_Catalog" />
</sequence>
答案 2 :(得分: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();
升级-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();