0

Hi ,
i am vipin facing a problem in mysql table
i hava two table, primary key of one table is used as a foreign key of another table.
but when i inserting some values in first table it gives
error:Cannot add or update a child row: a foreign key constraint

please give me solution for these problem !!!

4
Contributors
7
Replies
10
Views
6 Years
Discussion Span
Last Post by debasisdas
0

Hi ,
i am vipin facing a problem in mysql table
i hava two table, primary key of one table is used as a foreign key of another table.
but when i inserting some values in first table it gives and i also made a foreign key relation on child table = ON DELETE CASECAD
error:Cannot add or update a child row: a foreign key constraint

please give me solution for these problem !!!

0

post your table structure here (both tables)
have you tried adding rows directly through phpmyadmin, same error occurs there also?

Edited by urtrivedi: n/a

0

When you say 1st table, i assume that you are inserting into the Prent table and not into the child table.

This error arises if you try to do the reverse.
i.e.--trying to create a child record in the child table for which there is no parent record in the parent table.

0

No i am tring to insert into parent table also with child table,both together...!!
and if i do reverse ...these prob also arises !!

0

hELLO SIR...
IN
PRIMARI KEY TABLE (PID) IS PRIMARY KEY AND IN ANOTHER TABLE (PID) WORK AS FOREIGN KEY
AND WHEN I INSERTIG SOME VALUES IN BOTH TABLE ,IT GIVES EAROR ...
I MY USING SQLYOG COMMUNITY FOR DEGING RABLE AND FOREIGN KEY RELATIONSHIP

0

Hi,

First insert the row in parent table and save it after that insert in child table. This error comes when you try to insert a value in foreign key column which is not present in primary key column.

Good Luck.
Alok Pathak

0

insert into parent table only and see what happens.

if there is no error insert into dependent child table.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.