0

I have searched other answers and tried them, but no luck. Here is what I get: Error

SQL query:

ALTER TABLE `watching` ADD FOREIGN KEY ( `anime_Score` ) 
 REFERENCES `anime_15-12-2015`.`score` (`Score_ID`);

MySQL said: Documentation

1452 - Cannot add or update a child row: a foreign key constraint fails (anime_15-12-2015/#sql-fdc_14a, CONSTRAINT #sql-fdc_14a_ibfk_2 FOREIGN KEY (anime_Score) REFERENCES score (Score_ID))

Basicly I have a database called anime_15-12-2015 and in that database I have 3 tables: watching, type and score. I was able to add foreign key to type but no luck with score... If you need more info, reply what and I'll answer as soon as I can.

Thanx to everyone that tries to help me!

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
  • Expanding on what Drew said, if you have data in your tables that would violate the referential integrity of the foreign key, it will not let you create the foreign key. So is there data in the tables? – Brian S Dec 15 '15 at 22:49
  • I think Drew is stating you have orphaned records. `Select Score_ID from anime_15-12-2015 a LEFT JOIN watching b on a.score_ID = B.anime_Score where b.anime_Score is null` if any records come back, you're missing a parent record in anime_15-12-2015 for this record. – xQbert Dec 15 '15 at 22:50
  • 1
    possible dupe of http://stackoverflow.com/q/1253459 – Drew Dec 15 '15 at 22:50
  • happens on all CRUD operations except R. So all the CUD ops – Drew Dec 15 '15 at 22:50

1 Answers1

0

Check in the column 'anime_Score' of Table 'watching' if exist a value which no exist in the Table 'score' (Score_ID).

Thiago
  • 56
  • 4