Reputation: 134
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)
Upvotes: 1
Views: 123
Reputation: 150
I'm seeing a few problems in your statement. But to answer the question that was asked, look at the "language" table. The value you put in original_language_id must be one of the values in the language.language_id column (or null, see below).
As for the other stuff, several users have already commented on the null value. null is a keyword and should not be in quotes.
ALso, your last 4 values seem to be in a different order than the field list.
Upvotes: 0
Reputation: 1
It seems that "original_language_id" is a foreign key from the "language" table and the value which you are trying to insert i.e 'null' in this case is not in the parent table(language).
Upvotes: 0
Reputation: 1882
Looks like you are giving 'null' as value for original_language_id. Check, whether you have null as value in your language table. If you want to insert value null .... write it just null not 'null'.
Upvotes: 0
Reputation: 20955
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.
Upvotes: 0
Reputation: 91
The value for original_language_id must match the value of language_id for one row in the language table. This requirement is due to a foreign key on the film table.
If this value is an integer it should not be surrounded by quotes.
Upvotes: 1