How to Fix Foreign Key Constraint Fails in Magento
I am in the stage of migrating my local database of magento to public when I have encountered this error. How did it happen: 1.) I use ph...
https://www.czetsuyatech.com/2021/07/magento-foreign-key-constraint-fails-fix.html
I am in the stage of migrating my local database of magento to public when I have encountered this error.
How did it happen:
1.) I use phpmyadmin3.2 to export the sql statements.
2.) In my host mysql's phpmyadmin, I have executed the dump statements.
And I got the following error:
SQL query:
So what did I do:
1.) I simply re-dumped my local database sql statements using phpmyadmin this time checking "Disable foreign key contraints checkbox" and it executed without error.
See attached image for reference.
How did it happen:
1.) I use phpmyadmin3.2 to export the sql statements.
2.) In my host mysql's phpmyadmin, I have executed the dump statements.
And I got the following error:
SQL query:
--
-- Constraints for table `eav_entity_attribute`
--
ALTER TABLE `eav_entity_attribute` ADD CONSTRAINT `FK_EAV_ENTITY_ATTRIBUTE_ATTRIBUTE` FOREIGN KEY ( `attribute_id` ) REFERENCES `eav_attribute` ( `attribute_id` ) ON DELETE CASCADE ON UPDATE CASCADE ,
ADD CONSTRAINT `FK_EAV_ENTITY_ATTRIBUTE_GROUP` FOREIGN KEY ( `attribute_group_id` ) REFERENCES `eav_attribute_group` ( `attribute_group_id` ) ON DELETE CASCADE ON UPDATE CASCADE
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails (`db294125795/#sql-1357_3238a8`, CONSTRAINT `FK_EAV_ENTITY_ATTRIBUTE_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `eav_attribute` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE)
So what did I do:
1.) I simply re-dumped my local database sql statements using phpmyadmin this time checking "Disable foreign key contraints checkbox" and it executed without error.
See attached image for reference.
18 comments
Thanks, I was having the same issue migrating my magento database. now, all the queries were imported successfully. I appreciate the time you took to publish this post. cheers.
I was wondering if there is a solution for this.
Very helpful.
Thanks
You just save my life...
Sweet! Thanks buddy :-)
Thanks! Worked like a charm. :)
THANK YOU! lot of help!
Amaaazing! Thank you so much
And again: THANKS!!!
Thank you so much for posting this. I have a launch tomorrow and I couldn't upload the site without this.
Awesome. This saved me a lot of head-scratching!
awesome... you've just saved me lot's of time. Used your example to get syntax SET FOREIGN_KEY_CHECKS=0; which fixed the import error I was getting when I pasted the line into a data dump from Template Monster that wouldn't upload using phpmyadmin or using command line.
Hey Friend,
it's really great help, great job ;)
wow, works perfectly! Thanks man!
Thanks!
As somebody on the thread says, just adding SET FOREIGN_KEY_CHECKS=0 at the top of the commands fixes this issue.
Amaaazing! Thank you so much
thanks that worked!
You're awesome! Thank you for posting this fix!
Post a Comment