Wrong entity ID exception in install script
-
16-10-2019 - |
Question
I am trying to run this install script but I am getting an exception Wrong entity ID
. Tried debugging through debugger but I am not much familiar with the EAV architecture of Magento, so got lost.
Here is the portion of my config.xml
<resources>
<namespace_mymodule_setup>
<setup>
<module>Namespace_Mymodule</module>
<class>Namespace_Mymodule_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</namespace_mymodule_setup>
<namespace_mymodule_write>
<connection>
<use>core_write</use>
</connection>
</namespace_mymodule_write>
<namespace_mymodule_read>
<connection>
<use>core_read</use>
</connection>
</namespace_mymodule_read>
</resources>
I have defined the class by extending it from Mage_Eav_Model_Entity_Setup
class Namespace_Mymodule_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup {
}
And finally my install script contents are:
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute( 'quote_payment', 'b_transaction_id', array() );
$installer->addAttribute( 'order_payment', 'b_transaction_id', array() );
$installer->addAttribute( 'invoice', 'b_transaction_id', array() );
$installer->addAttribute( 'creditmemo', 'b_transaction_id', array() );
$installer->endSetup();
What's the error about? And Its a possibility that this script ran earlier successfully from a different module (this one is a rewrite) but I am not sure if it has then how to check for that?
Solution
The whole EAV around Mage_Sales is not anymore EAV. To add new attributes "the EAV-way" you have to use the Sales Setup class, which takes carr of the flat table design.
Try to change the setup class to Mage_Sales_Model_Resource_Setup
What magento version are you using?
OTHER TIPS
People getting this error in Magento2:
This seems to be an issue with dependency order during setup:upgrade with custom attributes. In Vendor/ModuleName/etc/module.xml, make sure to include a sequence tag for each of the modules your attributes depend on. If you're adding attributes to Products in your Setup/InstallData.php file, you need to include:
<sequence>
<module name="Magento_Catalog" />
</sequence>
In between your module declaration