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 magento.stackexchange.com, 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 community@magento.com.

Magento Forum

Integrity Constraint Violation
 
purplemine
Sr. Member
 
Total Posts:  143
Joined:  2008-05-20
London
 

Hi,

Great work! Google Base now works like a dream in 1.1.8 on a Multi-Website setup, thanks.

I am still getting the following error when trying to save products:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`pulseret_magento/catalog_category_product_index`, CONSTRAINT `FK_CATALOG_CATEGORY_PRODUCT_INDEX_CATEGORY_ENTITY` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`))

I have tried all solutions in the forum with no luck.  Any ideas?

John

 
Magento Community Magento Community
Magento Community
Magento Community
 
purplemine
Sr. Member
 
Total Posts:  143
Joined:  2008-05-20
London
 

Has anyone got any idea how to solve this, at present I am unable to update certain products!

 
Magento Community Magento Community
Magento Community
Magento Community
 
purplemine
Sr. Member
 
Total Posts:  143
Joined:  2008-05-20
London
 

OK I managed to fix the problem (which I still don’t know what caused it).

I had a look in the offending products catalog_product_entity table and noticed that there were 6 category id’s in the table where the product was only in 5 categories.  Once I had deleted the offending category ID from each product which had a problem then the error disappears.

I guess that the category was deleted at some point but the references were not.

I think this would probably be a bug in the system, I will create a new issue.

UPDATE:
It was not that problem at all.  It seems that the upgrade changed the status to one of my stores to disabled, which broke saving products (even if the products are not in that store).  I have enabled the store and all seems to be fine for now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
purplemine
Sr. Member
 
Total Posts:  143
Joined:  2008-05-20
London
 

Right, that didn’t fix this issue either, I’m at a loss now, I have run into more products that have this issue!

Anyone got any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
finch8243
Sr. Member
 
Total Posts:  79
Joined:  2007-08-31
 

I had the same problem and discovered some “stray categories”—ones that referred to parent_ids that did not exist.  I ran this query and found several:

SELECT entity_id FROM catalog_category_entity AS cce WHERE parent_id NOT IN (SELECT entity_id FROM catalog_category_entity AS cce2) AND parent_id>0

So what you want to do is write a PHP script to delete out those categories using the ‘category.delete’ API.  You could do it manually, but you have to delete from so many tables that you could make a mistake and leave out one.  Here’s an example of my query:

// Call SOAP
$proxy = new SoapClient('http://www.yoursite.com/magento/api/soap/?wsdl');
$sessionId $proxy->login('yourlogin''password');


// Get all up stray categories
    
mysql_select_db($yourmagentoinfo);
    
$query_rsBadCats "SELECT entity_id FROM catalog_category_entity AS cce WHERE parent_id NOT IN (SELECT entity_id FROM catalog_category_entity AS cce2) AND parent_id>0 "
    
$rsBadCats mysql_query($query_rsBadCats$magento) or die(mysql_error());
    
$row_rsBadCats=mysql_fetch_assoc($rsBadCats);
    
    do 
{
    
    
echo "Deleting ".$row_rsBadCats['entity_id']."<br>";
    
$allCategories $proxy->call($sessionId'category.delete'$row_rsBadCats['entity_id']);
    
    
while ($row_rsBadCats=mysql_fetch_assoc($rsBadCats));

I’m not sure why I had those strays—a lot of adding and deleting categories while I set up the store, probably.  Anyway, this query worked for me.

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