I cannot reindex the Product flat data because I get the following error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`fpshop/#sql-6101_1484e`, CONSTRAINT `FK_CAT_PRD_FLAT_1_ENTT_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CA)
Any ideas where to look to fix?
Go to your database and check all the rows in table catalog_product_entity or catalog_product_flat_1, particularly the values in column entity_id.
Most likely some rows are missing the required values, which means that either someone has messed with the db, or you are using a module, which is messing up the db. Either you will need to delete those broken rows, or fill them with values they are missing.
fix proposal:
In order to fix this, try to run a query below to locate the broken rows :
SELECT a.entity_id FROM catalog_product_flat_1 AS a LEFT JOIN catalog_product_entity AS b ON a.entity_id = b.entity_id WHERE ISNULL(b.entity_id);
And then delete those rows you got by doing
DELETE FROM catalog_product_flat_1 where entity_id = '123456789';
where 123456789 is the id of the broken row.
Have you tried disabling Flat_catalog_category and Flat_catlaog_product and then truncating the catalog_product_flat tables.Be sure to disable foreign key constraints checks by doing SET FOREIGN_KEY_CHECKS = 0; before truncating. Once doing that you should be able to manually reindex via ssh . A well documented solution for this issue is here : http://binarythoughts21.blogspot.in/2013/12/reindexing-problems-in-magento.html
Related
While adding product in Magento I am getting following error.
1062 Duplicate entry '24678-1' for key 'UNQ_MAGE_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID
I have followed solutions explained here, Integrity constraint violation in Magento custom module
Even after deleting entries from table as explained above,I am getting same error.
I am using Enterprise version 1.11.0.0
I have faced the same issue and debugging it since two days. finally I got the solution and fixed the issue.
This was occurred due to the inconsistency into database tables.
cataloginventory_stock_item
catalog_product_entity
I have removed the all inconsistency data using below query:
DELETE FROM cataloginventory_stock_item where product_id NOT IN (select entity_id from catalog_product_entity)
You can check how much records before perform the delete.
select count(*) from cataloginventory_stock_item where product_id NOT IN (select entity_id from catalog_product_entity)
I want to delete eav_attribute table from Magento database.
I am getting #1217 - Cannot delete or update a parent row: a foreign key constraint fails
How can i delete it safely?
You are walking on shallow ice here.
There is a high chance that this deleting the table will break your website. There are foreign keys to that table for example from catalog_eav_attribute and customer_eav_attribute. Also all the tables that hold attribute values are linked to eav_attribute.
Like catalog_product_entity_int for example.
If you want to add or update attributes from that table you should find an other way. Like using install scripts where you use '$this->addAttribute' or $this->updateAttribute.
I've drop a constraint unique key with command:
ALTER TABLE table
DROP CONSTRAINT UNIQUE uk_nome;
it's removed because I don't see it, but when I try to re-add it with different parameter:
ALTER TABLE tale ADD CONSTRAINT UK_name UNIQUE (uk_1, uk_2);
I receive the error:
Errore SQL: ORA-00955: name is already used by an existing object.
Where is the problem?
You drop uk_nome and then add uk_name. I mean that there is a typo in uk_nome.
Resolved, the unique key is present, like index, into the system in the table dba_objects
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3262-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'#
This appears when I am trying to add stock to my store, and obviously deletes what I have entered and doesn't let me add anything, help me fix this please, I'm not the most amazing on the computer, so please bare this in mind.
Thanks
Changing
$product->save();
to
$product->getResource()->save($product);
solved this problem for me
I have faced the same issue and debugging it since two days. finally I got the solution and fixed the issue.
This was occurred due to the inconsistency into database tables.
cataloginventory_stock_item
catalog_product_entity
I have removed the all inconsistency data using below query:
DELETE FROM cataloginventory_stock_item where product_id NOT IN (select entity_id from catalog_product_entity)
You can check how much records before perform the delete.
select count(*) from cataloginventory_stock_item where product_id NOT IN (select entity_id from catalog_product_entity)
May be this can help someone!
This error you can look in magento forum.
http://www.magentocommerce.com/boards/viewthread/300959/
This is error with sql index link. Yuo can use $product->getResource()->save($product); for resolve this problem.
https://stackoverflow.com/a/14152754/1844561
It took me hours on google trying to find the correct info that was easy to follow for an amature like me. Eventually using different sources, I figured out what I needed to delete and where I needed to delete it. The below worked for me, hope it works for you.
Go to your database
Find the table named "cateloginventory_stock_item
Delete the last few records on the list (at the bottom of the table)
Voila! You should now be able to enter new products.
1062 Duplicate entry '3262-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'#
from this its clear that there is some unique constraint and 3262 value already exist in data base.
I suggest you run reindexing and then check.
Basically some entry 3262 didnt got deleted from your stock table so a new entry is throwing error.
I was facing similar issue and fix which I have applied is as follow :
Error : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '59457-1' for key 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID'
Solution : There is a table called eav_entity_store, you will have to modify a record where sku / product ID is mentioned, Increase the Increment ID to + 1
and update that record in database. Once you update the Increment ID then you will be able to add the stock.
For Example: If "eav_entity_store" table has last increment_last_id as = 730354, then
I will have to update that record to 730355 and my problem will get resolved :)
SQL Query: update eav_entity_store set increment_last_id = '730355' where eav_entity_store.entity_store_id =$YourStoreID;
if the error showing for the table 'cataloginventory_stock_item' having 'UNQ_CATALOGINVENTORY_STOCK_ITEM_PRODUCT_ID_STOCK_ID' index,
then please sure that you are passing different product SKU from your script each time.because if you pass the same SKU then it will fetch the id of the product on the basis of that SKU and get the duplicate entry of that particular product id.
Also Never Use
$product->save();
to
$product->getResource()->save($product);
because it will not update your product details completely.
i am trying to import a sql dump of magento along with some product data and i get this foreign key constraint error:
`ERROR 1452 (23000) at line 231680: Cannot add or update a child row: a foreign key constraint fails:
`magento`.`#sql-b33_27`, CONSTRAINT `FK_CATALOG_COMPARE_ITEM_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE CASCADE ON )`
This is the sql code which is causing the error :
--
-- Constraints for table `catalog_eav_attribute`
--
ALTER TABLE `catalog_eav_attribute`
ADD CONSTRAINT `FK_CATALOG_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE;
I am not very comfortable with sql queries. Could some one please explain me what this query does and guide me to resolve this? Thanks.
You are trying to add a record into catalog_eav_attribute, but you do not have a corresponding record in eav_attribute that matches on attribute_id
If you are also inserting bulk data into eav_attribute, I would recommend doing that first, and then the data would be in the table before the foreign key on catalog_eav_attribute needed to reference it.
This article discusses how you can use:
SET FOREIGN_KEY_CHECKS = 0;
--Do your update here
SET FOREIGN_KEY_CHECKS = 1;
If you cannot change the order that you are inserting data. You just have to make sure your data follows the Foreign Keys once everything has been inserted into the database, before you can re-enable the FOREIGN_KEY_CHECKS
I used a database repair tool, after that did this in SQL:
DROP TABLE catalog_product_flat_1 ,
catalog_product_flat_2 ,
catalog_product_flat_3 ;
Now the index is built succesfully.