1

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)

5
  • 2
    Instead of 'null', you probably meant null (no single quotes) Commented Nov 1, 2016 at 17:09
  • The problem is obvious here, You put NULL as original_language_id, which violate foreign key constraint. Or if you allow null on the column, you probably should write it as NULL instead of 'null' Commented Nov 1, 2016 at 17:10
  • You are trying to insert a record a record which references a parent record in the languages table which does not exist or never did exist. This is a data problem most likely, rather than a problem with the design. Commented Nov 1, 2016 at 17:10
  • Excellent answers guys, little tip - you'll get much better reputation points if you post these as answers, not comments. Commented Nov 1, 2016 at 17:18
  • can u send your total query from create table to insert Commented Nov 1, 2016 at 17:18

5 Answers 5

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Ah yup. Thanks a ton! Rookie mistake.
0

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'.

Comments

0

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).

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.