Collins Harper Website Consulting

Skip to Main Content »

Search Site
Welcome to Collins Harper

You're currently on:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`starlit_mag/weee_discount`, CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE O) You don't run into this too often with Magento, but occationally you will run into it when using some product import or something else. The Integrity constraint is caused by a piece of data that is trying to be validated and does not exist (somewhere in the path of collecting the data it wasn't validated at all. So now we are getting a hard fail from the SQL server) So what are you to do? You will need Access to your MySQL server (console preferable or PMA) access to your MySQL error log In your MySQl client CREATE TABLE innodb_monitor (a INT) ENGINE=INNODB; then go repeat whatever you did to get the integrity constraint violation in Magento. if you now look in your MySQL error log you will have some data like this ===================================== 091008 17:46:15 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 16 seconds ---------- SEMAPHORES ---------- OS WAIT ARRAY INFO: reservation count 856317, signal count 855757 Mutex spin waits 0, rounds 5074326, OS waits 46022 RW-shared spins 1473407, OS waits 727074; RW-excl spins 86649, OS waits 61677 ------------------------ LATEST FOREIGN KEY ERROR ------------------------ 091008 17:33:37 Transaction: TRANSACTION 0 238197486, ACTIVE 0 sec, process no 12876, OS thread id 1175693632 inserting, thread declared inside InnoDB 500 mysql tables in use 1, locked 1 5 lock struct(s), heap size 1216, undo log entries 1 MySQL thread id 8398817, query id 114420582 67.22.130.10 MAGENTO_DB update INSERT INTO `weee_discount` (`entity_id`, `customer_group_id`, `website_id`, `value`) VALUES ('1492', '4', '1', '90.000000') Foreign key constraint fails for table `MAGENTO_DB/weee_discount`: , CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` FOREIGN KEY (`entity_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE Trying to add in child table, in index `FK_CATALOG_PRODUCT_ENTITY_WEEE_DISCOUNT_PRODUCT_ENTITY` tuple: DATA TUPLE: 2 fields; 0: len 4; hex 000005d4; asc ;; 1: len 6; hex 0000001efcfa; asc ;; But in parent table `MAGENTO_DB/catalog_product_entity`, in index `PRIMARY`, the closest match we can find is record: PHYSICAL RECORD: n_fields 12; compact format; info bits 0 0: len 4; hex 000005d5; asc ;; 1: len 6; hex 00000dc1347f; asc 4 ;; 2: len 7; hex 000000d1a21b16; asc ;; 3: len 2; hex 000a; asc ;; 4: len 2; hex 0009; asc ;; 5: len 6; hex 73696 d706c65; asc simple;; 6: len 7; hex 46464756413630; asc FFGVA60;; 7: len 6; hex 38372c313235; asc 87,125;; 8: len 8; hex 80001245c872d3e2; asc E r ;; 9: len 8; hex 80001245c873453c; asc E sE< ;; 10: len 2; hex 8000; asc ;; 11: len 1; hex 00; asc ;; ------------ TRANSACTIONS ------------ LIST OF TRANSACTIONS FOR EACH SESSION: ---TRANSACTION 0 238197607, not started, process no 12876, OS thread id 1172498752 MySQL thread id 8397106, query id 114422514 localhost MAGENTO_DB -------- FILE I/O -------- I/O thread 0 state: waiting for i/o request (insert buffer thread) I/O thread 1 state: waiting for i/o request (log thread) I/O thread 2 state: waiting for i/o request (read thread) I/O thread 3 state: waiting for i/o request (write thread) Pending normal aio reads: 0, aio writes: 0, ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0 Pending flushes (fsync) log: 0; buffer pool: 0 18070287 OS file reads, 1597418 OS file writes, 785462 OS fsyncs 3.44 reads/s, 17277 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s ------------------------------------- INSERT BUFFER AND ADAPTIVE HASH INDEX ------------------------------------- Ibuf: size 1, free list len 11, seg size 13, 617406 inserts, 617406 merged recs, 182758 merges Hash table size 17393, used cells 5409, node heap has 11 buffer(s) 71.43 hash searches/s, 805.07 non-hash searches/s --- LOG --- Log sequence number 5 342551995 Log flushed up to 5 342551995 Last checkpoint at 5 342551995 0 pending log writes, 0 pending chkp writes 571364 log i/o's done, 0.00 log i/o's/second ---------------------- BUFFER POOL AND MEMORY ---------------------- Total memory allocated 95065234; in additional pool allocated 1048576 Buffer pool size 512 Free buffers 0 Database pages 501 Modified db pages 0 Pending reads 0 Pending writes: LRU 0, flush list 0, single page 0 Pages read 20571252, created 31118, written 1058853 3.62 reads/s, 0.00 creates/s, 0.00 writes/s Buffer pool hit rate 999 / 1000 -------------- ROW OPERATIONS -------------- 0 queries inside InnoDB, 0 queries in queue 1 read views open inside InnoDB Main thread process no. 12876, id 1171433792, state: sleeping Number of rows inserted 1164362, updated 109975, deleted 549009, read 3248737709 0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 3771.89 reads/s ---------------------------- END OF INNODB MONITOR OUTPUT ============================ What we are interested in is the insert into line You will then need to track back the save statement to where it got it's data from in the Mage app folder and find out which table has erroneous data.