Oracle parent key not found

I am trying to add a constraint to the booking table, reservations can be for flight or accommodation or both.

Reservation

  • First 4 entries of booked domestic flights, departure and accommodation
  • The next 4 entries have booked a flight only and have acc_id

    forNULL

  • After two entries, only accommodation is booked, so in-flight, out-of-flight, and seats are set to null.

Here are my limits for this table

ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT HOLIDAY_PK PRIMARY KEY (RESV_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT CUSTOMER_FK FOREIGN KEY (BOOKING_CUS_ID) REFERENCES CUSTOMER (CUS_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT STAFF_FK3 FOREIGN KEY (EMP_ID) REFERENCES STAFF (EMP_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK FOREIGN KEY (IN_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK1 FOREIGN KEY (OUT_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);
ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT ACC_FK FOREIGN KEY (ACC_ID) REFERENCES ACCOMMODATION (ACC_ID);

      

and the only limitation that gives the error is:

ALTER TABLE HOLIDAY_RESERVATION ADD CONSTRAINT FLIGHT_FK1 FOREIGN KEY (OUT_FLIGHT_ID) REFERENCES FLIGHT (FLI_ID);

      

I get

ERROR at line 1:
ORA-02298: cannot validate (U1146815.FLIGHT_FK1) - parent keys not found

      

What's the problem? I understand that it has to do with orphans, but I am setting zeros, so I don't understand, please advise

+3


source to share


2 answers


The error indicates that the table FLIGHT

has no entry for at least one of the values FLI_ID

between 11 and 18. You will need to insert a row into the table FLIGHT

for any flights missing or update the table to have a different one OUT_FLIGHT_ID

.



+14


source


Remove all rows from the child table that are used to modify the referenced column.



ALTER TABLE sales ADD CONSTRAINT sales_time_fk
FOREIGN KEY (time_id) REFERENCES times (time_id) 
RELY DISABLE NOVALIDATE;

      

+2


source







All Articles