Can anyone tell me what i'm doing wrong here?I'm trying to set up a one-to-one relationship between two tables, but it just doesn't work.These are my tables:
And this is the insert statement i'm using to populate them(I'm getting the following error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`video_library `.`films`, CONSTRAINT `films_ibfk_5` FOREIGN KEY (`film_id`) RE
FERENCES `prices` (`id`)))
Thanks in advance
Code:
CREATE TABLE prices
(
id INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,
price FLOAT NOT NULL
) ENGINE=INNODB ;
CREATE TABLE films
(
film_id INT AUTO_INCREMENT NOT NULL PRIMARY KEY ,
name VARCHAR(30) NOT NULL,
FOREIGN KEY (film_id) REFERENCES prices (id)
) ENGINE=INNODB ;
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`video_library `.`films`, CONSTRAINT `films_ibfk_5` FOREIGN KEY (`film_id`) RE
FERENCES `prices` (`id`)))
Code:
INSERT INTO prices (price)
VALUES (1.99),
(2.99),
(3.99),
(4.99),
(5.99),
(6.99),
(7.99),
(8.99),
(9.99),
(10.99),
(11.99),
(12.99),
(13.99);
INSERT INTO films (name)
VALUES ('The Godfather'),
('The Godfather II'),
('The Shawshank redemption'),
('Pulp fiction'),
('12 Angry men'),
('Schindler\'s List'),
('Fight club'),
('Inception'),
('The green mile'),
('Dog Day Afternoon'),
('The Dark Knight'),
('Saving Private Ryan'),
('Se7en');
Comment