no

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...

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:


--
-- 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.

Related

web-platform 7177135130929962841

Post a Comment Default Comments

18 comments

Leonardo Arias said...

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.

Unknown said...

I was wondering if there is a solution for this.
Very helpful.
Thanks

testes said...

You just save my life...

Unknown said...

Sweet! Thanks buddy :-)

David said...

Thanks! Worked like a charm. :)

#03 Thales said...

THANK YOU! lot of help!

Anonymous said...

Amaaazing! Thank you so much

Anonymous said...

And again: THANKS!!!

Anonymous said...

Thank you so much for posting this. I have a launch tomorrow and I couldn't upload the site without this.

Angel Bean Baby Shoes said...

Awesome. This saved me a lot of head-scratching!

Anonymous said...

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.

Anonymous said...

Hey Friend,

it's really great help, great job ;)

modra ideja said...

wow, works perfectly! Thanks man!

Souzace said...

Thanks!

Unknown said...

As somebody on the thread says, just adding SET FOREIGN_KEY_CHECKS=0 at the top of the commands fixes this issue.

izdelava spletnih strani said...

Amaaazing! Thank you so much

Anonymous said...

thanks that worked!

Anonymous said...

You're awesome! Thank you for posting this fix!

item