سؤال

I added some images to my local site and after this when going to the product detail page I got the Magento error page saying that there has been an error processing your request and Image file was not found. After this the product flat data says that it needs to be re-indexed but when I try to re-index it, it says There was a problem with reindexing process. I assume the images are related to the issue as it didn't need reindexing prior to this. I deleted the product that I had uploaded images for, I deleted the cache and cleared the lock files as had been suggested on another post similar to this that I found. Can anyone suggest any further actions I can take to debug this.

<--- FURTHER DETAILS ---> I ran the reindex file in the console and it returned the following error

   Product Flat Data index process unknown error:
exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`startlondon_live`.`#sql-448_15e`, CONSTRAINT `FK_MAG_MAG_CAT_PRD_FLAT_1_ENTT_ID_MAG_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `mag_catalog_product_entity` (`entity_id`) ON DE)' in /home/start-london/public_html/lib/Zend/Db/Statement/Pdo.php:228

The only thing I could think of was to turn off foreign key restraints in the database but this didn't help

هل كانت مفيدة؟

المحلول

Hoping I understood the problem at hand: and the question...

This part of the error message is telling:

startlondon_live`.`#sql-448_15e`, CONSTRAINT `FK_MAG_MAG_CAT_PRD_FLAT_1_ENTT_ID_MAG_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `mag_catalog_product_entity` (`entity_id`)...

What this is telling me is that the column startlondon_live is referencing a catalog product entity id column (mag_catalog_product_entity) on the entity field but that entry or field no longer exists. The name of the foreign key is not formatted as the Magento installer would name it, so that tells me it is custom.

In essence the constraint you've created from another table is failing in the indexer because the target column either no longer exists or will be deleted, orphaning the child.

This brings me to a few thoughts:

  • When creating new fields in either custom resource models or to extend the Magento catalog it is unnecessary to modify flat tables.
  • It may also be unnecessary to create foreign key relationships to entity_id's on flat tables. FK relationships enforce schema and prevent data errors or orphaned content but, at the heart of Magento, EAV makes no effort to enforce this schema. Flat tables are built on-the-fly and attributes which expose themselves as Frontend attributes will automagically create necessary columns for the flat tables.
  • In the case that this is a custom resource model you don't need to have a FK relationship to the flat table -- instead create the FK relationship to the catalog_product_entity table; after all, that's the entity of record in Magento for a product. You may still define your ON DELETE rules.

In the end you'll need to fix this error. Disabling foreign key checks is a recipe for disaster.

Instead, remove your schema edits from Magento DB. Disable/enable flat catalog - or in the worst-case scenario drop your catalog_product_flat* tables and rebuild them.

نصائح أخرى

Fixing this

In order to fix this issue, you need to find what the corrupted entries are. This is easy. In this case, you’ll need to create a query to get the empty registers:

SELECT a.entity_id FROM catalog_product_flat_2 AS a LEFT JOIN catalog_product_entity AS b ON a.entity_id = b.entity_id WHERE ISNULL(b.entity_id);

This will display the corrupted entities. You only need to delete them and that’s all.

+-----------+
| entity_id |
+-----------+
|     35427 |
|     35428 |
+-----------+
2 rows in set (0.04 sec)

As example:

DELETE FROM catalog_product_flat_2 where entity_id = '35427';
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top