简体   繁体   中英

MySQL #1452 - Cannot add or update a child row: a foreign key constraint fails ON DELETE CASCADE ON UPDATE CASCADE)

I have 2 tables about music: songs and images, songs stores the song id, name, year, artist, audio. Artist is an indexed field it is in the images to identify the artist image. The problem happens when i want to insert a song in songs. appears this error:


INSERT INTO `songs` (`id`, `name`, `artist`, `year`, `audio`) VALUES ('0', 'x', 'x', '1000', 'x.mp3')
#1452 - Cannot add or update a child row: a foreign key constraint fails (`audio_player`.`songs`, CONSTRAINT `songs_ibfk_1` FOREIGN KEY (`artist`) REFERENCES `images` (`artist`) ON DELETE CASCADE ON UPDATE CASCADE)

both tables are empty.

any idea?

Well, i came too late, but: the error it's because i had to insert into images before of data of artist table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM