Reputation: 55
Im trying to make a simple data base but when i try to add data to either the album of song tables i get this error.
ERROR 1452: 1452: Cannot add or update a child row: a foreign key constraint fails (newschema
.songs
, CONSTRAINT fk_Songs_Albums1
FOREIGN KEY (Albums_AlbumId
) REFERENCES Albums
(AlbumId
) ON DELETE NO ACTION ON UPDATE NO ACTION)
SQL Statement:
INSERT INTO newschema
.Songs
(SongTitle
) VALUES ('Song1')
Im not sure if the structure is correct at all! but I am pretty desperate to get this working! Any help would be really appreciated.
Thanks
Upvotes: 0
Views: 1126
Reputation: 204774
You are using this query
INSERT INTO newschema.Songs (SongTitle) VALUES ('Song1')
So you insert a new song without a reference to any album. According to your schema that does not work. Every song must belong to an album.
So it should be at least something like this
INSERT INTO newschema.Songs (SongTitle, Albums_AlbumId)
VALUES ('Song1', 1)
Upvotes: 1