1452 Cannot add or update a child row a foreign key constraint fails mysql phpmyadmin 2022
1452 Cannot add or update a child row a foreign key constraint fails mysql phpmyadmin 2022
1452 Cannot add or update a child row a foreign key constraint fails mysql phpmyadmin 2022
The MySQL ERROR 1452 happens when you try to execute a data manipulation query into a table that has one or more failing foreign key constraints. The cause of this error is the values you’re trying to put into the table are not available in the referencing (parent) table.
How do I fix foreign key constraint failure? The error message itself showing there is a foreign key constraint error, which means you are deleting a parent table where the child table contains the Primary table identifier as a foreign key. To avoid this error, you need to delete child table records first and after that the parent table record.
Why Cannot add or update a child row? The error comes when you are trying to add a row for which no matching row in in the other table. “Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table.
Content
10.8 -> hello everybody welcome to our new video uh today
we want to fix this error which is a error number
18.08 -> 1452 is my mysql error so what i did i tried
to put i was trying to put a foreign key
30.08 -> on this table so i've created a subject id
which is 11 inch but now you can see here
36.88 -> when i go and i say i want to to
put a foreign key what it does uh
46 -> let me say subject id this is
something crazy sub object id
56.96 -> which is that get it there so we go here
and we take it and we say subject id
67.84 -> um what is that okay let me see yes then
we go here and we try to get the database
78.08 -> this database we're using then we come
and we look for the table we want to
85.44 -> to get its primary key to be our foreign key in
this table so we're trying to get that tbr subject
95.68 -> this one we got it so it gets it
automatically if i say on cascade
102.88 -> i want on delete if that it deleted that site
it can be deleted this side so if i want to
110.72 -> also edit that site to be edited that's this side
so when we try to save this we get into problems
120.8 -> if i say okay you can see i can see we get
into problems let's go and analyze our data
130 -> that we're going to see that it's a
0 0 0 0 here and in the table here
140.48 -> we want to make a foreign key let me
get you to that table appearance um
150.4 -> please come no the table is called subject
table um can't see it here but i'm gonna get it
162.56 -> subject subject i can't seem
to see it but i'm gonna see it