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

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

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

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.

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

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

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

insert into parent table only and see what happens.

if there is no error insert into dependent child table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.