BoostedMonkey BoostedMonkey - 1 month ago 14
SQL Question

SQL Insert command error

Here is my SQL:

INSERT INTO film (film_id, title, description, release_year, language_id, original_language_id,
rental_duration, rental_rate, length, replacement_cost, rating, special_features, last_update)
VALUES ('1001','1 st Grade FBI Agent','An undercover FBI agent must pretend to be
a 1st grade teacher to catch the bad guy', '2014','2','null', '5', '4.99', '123', '2014',
'20.99', 'PG-13', 'Tailers');


Here is the error I get when I run it. This is a preset database I'm using for an assignment for a class, and I was told to insert a new row into the film table.

Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (
sakila
.
film
, CONSTRAINT
fk_film_language_original
FOREIGN KEY (
original_language_id
) REFERENCES
language
(
language_id
) ON UPDATE CASCADE)

Answer

Your SQL Statement is trying to INSERT 'null' value for the original_language_id field in the film table.

It looks like this original_language_id is a FOREIGN KEY that references the language_id in the language table and is likely the PRIMARY KEY on that table.

Comments