Skip to content
Advertisement

Why am I violating an integrity constraint? (ORA-02291)

When I try to alter one of my tables to set one of it’s rows as a foreign key, I get the following error: “ORA-02291: integrity constraint (SYSTEM.M_FRAN_FK) violated – parent key not found”

This error only occurs when I insert a row into the database with a none-null value. I’m trying to understand why it’s doing this and what exactly I’m doing wrong. Here’s the sql code;

Advertisement

Answer

You need the “Marvel: Iron Man” franchise to exist before you insert “Iron Man” into Movie.

Also, you should always use explicit column names in INSERT statements.

…and more controversially, I feel database tables should have plural names if the table represents an unbounded collection. (I look forward to the dozen or so comment replies from people who disagree 😉 )

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement