mysql - SQL Code - Cannot add or update a child row -


i have created database , added tables no bother, trying add data tables keep getting error:

error 1452: (23000): cannot add or update child row: foreign key constraint fails (music,track, constraint track_ibfk_1 foreign key (genre_id) references genre(genre_id))

tables:

create table genre ( genre_id int not null auto_increment, genre_name varchar(10), primary key (genre_id) );  create table artist ( artist_id int not null auto_increment, artist_name varchar(20), primary key (artist_id) );  create table track    ( track_id int not null auto_increment, artist_id int not null, genre_id int not null, track_name varchar(50), primary key (track_id), foreign key (genre_id) references genre (genre_id), foreign key (artist_id) references artist (artist_id) );  create table location  ( location_id int not null auto_increment, location_name varchar(25), primary key (location_id) );  create table user  ( user_id int not null auto_increment, genre_id int not null, location_id int not null, user_fname varchar(10), user_lname varchar(10), user_age int, user_gender bit, primary key (user_id), foreign key (genre_id) references genre (genre_id), foreign key (location_id) references location (location_id) );  

the next line of code causes error , other tracks written whatever problem @ line solution?

insert `music`.`track`(`track_name`,`artist_id`,`genre_id`) values  ('next episode',2,1); 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -