# MYSQL foreign key constraint failed

**URL:** <https://www.phphelp.com/t/mysql-foreign-key-constraint-failed/32783>\
**Category:** MySQL database\
**Created:** [November 10, 2020, 7:23am UTC](https://www.phphelp.com/t/mysql-foreign-key-constraint-failed/32783 "2020-11-10T07:23:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vbwaj](https://www.phphelp.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@vbwaj](https://www.phphelp.com/u/vbwaj)\
**Post date:** [November 10, 2020, 7:23am UTC](https://www.phphelp.com/t/mysql-foreign-key-constraint-failed/32783/1 "2020-11-10T07:23:59Z")

</div>

Hello  
I have two tables pre\_exp\_details(parent) and post\_exp\_details(child).  
Firstly I had set a foreign key to post\_exp\_details from another table called mfd(parent).  
Now I want to change the foreign key of post\_exp\_details from table pre\_exp\_deatils.  
But I am getting foreign key constraint failed error. How to solve this problem.

 ![pre_exp](https://www.phphelp.com/uploads/default/original/2X/8/87b2246b6df1d62847cb9ef0187c091a93a22e76.png).

---

<div class="post-metadata">

**Author:** ![skawid](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/bbe5ce/32.png) [@skawid](https://www.phphelp.com/u/skawid)\
**Post date:** [November 10, 2020, 10:04am UTC](https://www.phphelp.com/t/mysql-foreign-key-constraint-failed/32783/2 "2020-11-10T10:04:02Z")

</div>

This probably means that your constraint is not valid given the current data in the tables - an entry in `post_exp_details` doesn’t have a corresponding entry in `pre_exp_details`. If you give us the structure of both tables and the foreign key you’re trying to set up, we can help you more.
