Reputation: 35
I would like to get help for the mentioned problem below:
SQL query: Copy
INSERT INTO kurs SET name='Bangla', freiePlaetze=10 ON DUPLICATE KEY UPDATE ersteller=1
MySQL said: Documentation
#1452 - Cannot add or update a child row: a foreign key constraint fails (
learner
.kurs
, CONSTRAINTkurs_ibfk_1
FOREIGN KEY (ersteller
) REFERENCESbenutzer
(bnummer
))
Upvotes: 0
Views: 31
Reputation: 74710
You've told MySQL "Insert into the kurs table, these values.. and if they already exist, change the ersteller
column of the existing row so its value is 1"
But ersteller
is linked to a parent column bnummer
in the bnutzer
table, and there is no row where bnummer = 1
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=90ab193e86d661b4341343efc459b492
Insert a row into benutzen
first, where the bnummer
column is 1
Upvotes: 1