Skip to content
Advertisement

Can’t enable a foreign key in ORACLE SQL

So I have a disabled foreign key (Manager_ID in the table Employees) and I wanted to enable it, but I get this error:

ORA-02298: cannot validate (my_username.EMP_MANAGER_FK) – parent keys not found

And this is the code:

Here’s how the table was created:

Advertisement

Answer

There are values in the column that are invalid from the foreign key’s perspective.

Assuming that you have a self-referencing foreign key like:

Then the error message indicates that there are manager_ids that do not exists in column employee_id. You can exhibit the offending rows with a query like:

You need to fix this before you can enable the foreign key.

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