3

What Innodb query can I use to correct the following problem?

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (mrvallar_magdb.catalog_product_entity_varchar, CONSTRAINT CATALOG_PRODUCT_ENTITY_VARCHAR_IBFK_3 FOREIGN KEY (entity_id) REFERENCES catalog_product_entity_orig (entity_id) ON DELETE)

Machavity
  • 30,841
  • 27
  • 92
  • 100
Road Ready
  • 31
  • 2

2 Answers2

2

You try to insert/update a record in catalog_product_entity_varchar with an entity_id value that does not exist in catalog_product_entity_orig

You'll need to insert that entity in the "orig" table before you can reference it in "varchar" table

Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
  • This is a Magento error and I can't alter the core code. Is there a query I can use on the DB to clean up these stray ids? – Road Ready Oct 15 '12 at 03:06
0

You try to insert a record having a foreign key which does not exist in the reference table. This is the cause of the issue you experience.

You will need to check why the referenced id does not exist and remedy the situation. Possible solutions:

  1. You can fix your data and make sure you will have no such inconsistencies in the future.

  2. You can check whether all the referenced values exist and if not, insert them before your problematic insertion

  3. You can insert-select into your table with checking the existence of the referred record in the where clause.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175