I've created a query out of 3 dependent tables:
car parts(id, name, value);
car_model(id, name,price);
part_and_model(car_model_id, car_part_id)
I get my car models from a list of values, and for car_id I use sequence for increment.
I have all the needed fields from my query, but now I want to insert data into car_parts and part_and_model at the same time. I've created two processes on submit to insert (the first for car_parts(fk) and the second for part_and_model). When I run this, I get this error and no data gets inserted into the tables:
ORA-02291: integrity constraint (PRACTICE.FK_CAR_PART_car_part) violated - parent key not found
When I delete the second process, the data is correctly inserted into the car_parts table. Why is this happening? Does the second process execute before first? What else am I missing?
item P8_CAR_MODEL = LOV; item P8_ID=>sequence: SELECT CP_SEK.NEXTVAL FROM DUAL;
process1:insert into CAR_PARTS(CP_ID,CP_NAME,CP_PRICE) VALUES (:P8_ID, :P8_NAME, :P8_PRICE);
process2: insert into part_and_model(PART_ID, MODEL_ID) values (:P8_ID,:P8_CAR_MODEL);
EDIT:
I managed to insert into car_parts table, but the error still says that the parent cannot be found (even though) it's in the table, so it must be the sequence... here is my code: process1: begin select PART_SEK.NEXTVAL INTO :P8_ID from dual;
insert into car_parts(id,name,value) VALUES (:P8_ID, :P8_NAME, :P8_PRICE); end;
process2:
insert into part_and_model(car_model_id, car_part_id) values (:P8_MODEL,:P8_ID);
EDIT2: when i use PART_SEK.currval instead of p8_id in second process, it works Once again, thank you all for your time.