4

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?

Zabs
  • 13,852
  • 45
  • 173
  • 297

3 Answers3

5

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.

Simon H
  • 2,495
  • 4
  • 30
  • 38
3

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>
sianguish
  • 31
  • 1
  • Hi @sianguish, I solved one issue with this, but then it appeared again in the Magento-Downloadable module, which I didn't modify. Do you have any clue? – Cyberdelphos Sep 19 '18 at 18:58
  • 1
    Just note. I have seen time and time again eav setup placed in the install/upgradeSchema files. The schema of the database is not changing here and therefore should properly be place in install/upgradeData scripts. The issue why you run into 'Wrong Entity ID' on installs is that the schema for the Magento_Catalog has been created but there is no data in the table which is why you get the error. Placing your code in the proper upgrade script solves this issue. – DOfficial Jun 24 '19 at 20:27
0

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();
Mukesh
  • 7,630
  • 21
  • 105
  • 159