문제

I have the following installer script - when I try to run this I get the following Magento error:

Error in file: "/vagrant/site.com/public_html/app/code/local/SS/Raptor/sql/raptor_setup/install-0.0.1.php" - Wrong entity ID

My installer script is as follows:

$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();

Any ideas why this might be happening?

도움이 되었습니까?

해결책

You are using the wrong setup class. You could use Mage_Customer_Model_Entity_Setup to add the attributes this way. See this answer to use Mage_Eav_Model_Entity_Setup to add customer attributes.

Additional quote attributes require a different setup class. You can use Mage_Sales_Model_Resource_Setup as model here.

다른 팁

Magento2 Fix:

You need to include your dependencies in your ModuleName/etc/module.xml file. I was adding a custom attribute for Products and had to include:

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

As you are trying to create attribute for two different entities use following code in 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>

In Setup.php file write following code.

class Namespace_Module_Model_Resource_Setup extends Mage_Customer_Model_Resource_Setup
{

}

Then after create two separate installer & upgrade files

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top