Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email

Magento Forum

Integrity constraint violation creating Product in Magento
Jr. Member
Total Posts:  2
Joined:  2012-10-03

i’m trying to Create a Product from magento Frontend, but when execute the php code i receive this error:

SQLSTATE[23000]Integrity constraint violation1452 Cannot add or update a child rowa foreign key constraint fails (`magento`.`catalog_product_entity`, CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_IDFOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON DE)

I found here that should be a problem with attribute set ID, but i tried force the ID from eav_attribute_set table, then with the function:


And with this function above but with “Default” value. Nothing change. So maybe the problem is not Attribute Set ID?

This is my code:

$product Mage::getModel('catalog/product');

$product->setName("Evento senza nome");
$attributeSetId Mage::getModel('catalog/config')->getAttributeSetId('catalog_product','Set_evento');
$product->setVisibility(4); // catalog, search
$product->setStatus(1); // enabled

// assign product to the default website

// for stock
$stockData $product->getStockData();





Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top