1

we're facing integrity constraint violation errors while importing products (and the corresponding categories) with category_flat setting activated.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`XXXXXXXXX`.`catalog_category_flat_store_1`, CONSTRAINT `FK_CAT_CTGR_FLAT_STORE_1_ENTT_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`entity_id`) REFERENCES `catalog_category_entity` (`entity_id`)

Is there a way to programmatically disable category flat tables before importing products? After the import proccess the indexes are getting refreshed.

Thanks!

1 Answers1

1

I would give this a try:

This will disable indexing before import, and re-enable afterwards.

Also you could look into the configuration xpath of catalog/frontend/flat_catalog_category

Or if you are directly importing via an .SQL file, look to disable Foreign key constraints at the top of the .SQL file, and re-enable the check at the end.

Also keep in mind you can drop the table: catalog_category_flat_store_1 and the index process will recreate it if such is required.

Community
  • 1
  • 1
B00MER
  • 5,471
  • 1
  • 24
  • 41
  • Hey, thanks for the answer. We already implement your suggestion concerning indexing process but this dosen't clear the table containing flat data. I thougt about your latest suggestion to drop the flat table but I had concerns dropping any table in the DB. Now I'll give it a try... – kaptankorkut Dec 13 '12 at 16:47
  • 1
    Yes, you should be safe dropping the table. Those tables are created dynamically by the indexer, as B00MER said. The _1 is the store_id that the flat table applies to. – Tim Reynolds Dec 13 '12 at 17:13
  • 1
    Thanks for the answers guys! Dropping or truncating the table caused errors because the product import tries to write to this table as long as the configuration xpath "catalog/frontend/flat_catalog_category" is set to 1. @B00MER, your second suggestion worked for me. – kaptankorkut Dec 14 '12 at 13:10