Why ORA-02291 Happens

  • Inserting child records before committing or inserting the parent record.
  • Data load ordering issue during batch migrations.

Recommended Resolution

Look up the parent constraint via R_CONSTRAINT_NAME in ALL_CONSTRAINTS and insert parent rows first (or use DEFERRABLE INITIALLY DEFERRED constraints for circular graphs).

SQL Diagnostic & Fix Example

SELECT c.table_name AS child_tbl, p.table_name AS parent_tbl
FROM all_constraints c JOIN all_constraints p ON c.r_constraint_name = p.constraint_name
WHERE c.constraint_name = 'FK_LEDGER_CUST';