In: Computer Science
I get an error 1452 saying it cannot add or update my foreign key. is there a way to fix this
Error Because you directly Inserting in Child Data you have to insert first in Parent Table otther wise it could not be inserted Here i gave you small Example same thing whith me and how i solved it
Create table Employee(eid int Primary Key,ename varchar(20),age
INT,salary double);
desc Employee;
Create table Works(eid int,did int,pct_time int,CONSTRAINT Works_fk
FOREIGN KEY (eid) REFERENCES Employee (eid));
desc Works;
/*Try to insert in directly Child but phasing problem */
insert into Works values(101,1001,100);
/*After inserting in Parent it we can be insert*/
insert into Employee values(101,'Andrew Fuller',40,50000);
Select * from Employee;
insert into Works values(101,1001,100);
Select * from Works;
if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........