-1

I am continuously getting this flag:

1452 - Cannot add or update a child row: a foreign key constraint fails (mydb4653.stars, CONSTRAINT fk_stars_movie FOREIGN KEY (movieID) REFERENCES movie (id))

when I try to insert the data into the table

These are the tables

movie(id, title, relYear, category, runTime, director,
studioName, description, rating)
actor(aID, fName, surname, gender)
stars(movieID, actorID)
movGenre(movieID, genre)

I think it could have something to do with the fact that its not the only movieID as it is the only one I am having issues with. It is definitely indexed

I have tried:

CREATE TABLE stars
(movieID INTEGER,
actorID INTEGER NOT NULL PRIMARY KEY,
CONSTRAINT fk_stars_movie FOREIGN KEY (movieID) REFERENCES movie(ID)
);

as well as manually making it the foreign key in the relation view. It is also the same data type as its primary key so that's not the issue either.

CREATE TABLE movie
(id INTEGER NOT NULL PRIMARY KEY,
 title VARCHAR(100), 
 relYear INTEGER, 
 category VARCHAR(5), 
 runTime INTEGER, 
 director VARCHAR(50), 
 studioName VARCHAR(100), 
 description VARCHAR(500), 
 rating DECIMAL(10,2)
);
Jade
  • 25
  • 5
  • 1
    Possible duplicate of [ERROR 1452: Cannot add or update a child row: a foreign key constraint fails](https://stackoverflow.com/questions/21659691/error-1452-cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails) – Madhur Bhaiya Nov 22 '18 at 13:08
  • I'm curious to see the `CREATE TABLE movie` script and the insert query you're using – Cid Nov 22 '18 at 13:13
  • You can not `update` or `insert` in child table without it parents. – Sadikhasan Nov 22 '18 at 13:13
  • @Cid I've edited the question to show the CREATE TABLE movie query, for the insert query it's :INSERT INTO stars VALUES and then copied and pasted values which worked for every other table – Jade Nov 22 '18 at 13:21
  • well, this is the `VALUE` part that is relevant – Cid Nov 22 '18 at 13:23

1 Answers1

0

set foreign_key_checks=0;

Your insert query goes here...

set foreign_key_checks=1;

Krishna
  • 438
  • 5
  • 18