aspose file tools*
The moose likes JDBC and the fly likes ORA-02291: integrity constraint violated - parent key not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ORA-02291: integrity constraint violated - parent key not found" Watch "ORA-02291: integrity constraint violated - parent key not found" New topic
Author

ORA-02291: integrity constraint violated - parent key not found

raj chopra
Ranch Hand

Joined: Apr 09, 2012
Posts: 60
Hi All,
I need to insert some new date in table called state,when doing so i am facing an error mentioned below.
below i furnished the query i used and the constraints involved both the tables,please guide me to resolve the error so that i can insert the new data
into state table.

query used:
INSERT INTO STATE (COUNTRY_CODE,STATE_CODE,NAME,CREATED_BY,DATE_CREA TED ,
TAX_PERCENTAGE,TIMEZONE_ID,DAYLIGHT_SAVING)
VALUES(3,'AG','Aguascalientes','User01','05-APR-13',0,1,1)
/

ERROR at line 1:
ORA-02291: integrity constraint (PRODUCT1.FK_STATE_TIMEZONE_ID) violated - parent key not found

the constraints in state table are :

TABLE_NAME CONSTRAINT_NAME CONSTRAINT STATUS
------------------------------ ------------------------------ ---------- --------
STATE FK_STATE_UPDATED_BY Foreign ENABLED
STATE FK_STATE_TIMEZONE_ID Foreign ENABLED
STATE FK_STATE_CREATED_BY Foreign ENABLED
STATE FK_STATE_COUNTRY_CODE Foreign ENABLED
STATE SYS_C004002 Check ENABLED
STATE SYS_C004003 Check ENABLED
STATE SYS_C004004 Check ENABLED
STATE SYS_C004005 Check ENABLED
STATE SYS_C004006 Check ENABLED
STATE PK_STATE Primary ENABLED


constraints in timezone table are


TABLE_NAME CONSTRAINT_NAME CONSTRAINT STATUS
------------------------------ ------------------------------ ---------- --------
TIMEZONE FK_TIMEZONE_UPDATED_BY Foreign ENABLED
TIMEZONE FK_TIMEZONE_CREATED_BY Foreign ENABLED
TIMEZONE SYS_C004070 Check ENABLED
TIMEZONE SYS_C004071 Check ENABLED
TIMEZONE SYS_C004072 Check ENABLED
TIMEZONE SYS_C004073 Check ENABLED
TIMEZONE PK_TIMEZONE_ID Primary ENABLED


Reagrds,
raj chopra
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1

The column FK_STATE_TIMEZONE_ID seems to have a foreign key constraint. I suppose it is dependent on another table. You would need to insert the value in the parent table before you can senter the same in this one.
raj chopra
Ranch Hand

Joined: Apr 09, 2012
Posts: 60
Hi Rajkamal Pillai,

thaks for reply.

The parent table(timezone) is having the same data which need to be refered in child table (state). but how should i refer that particular row of parent table which should be inserted/refered in child table?

Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

If I'm not misreading it, you're inserting a value of 1 into the TIMEZONE_ID column. Your TIMEZONE table should therefore have a record with a value of 1 in its primary key column. Try to verify this (by selecting rows where the primary key equals to 1 from the TIMEZONE table).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ORA-02291: integrity constraint violated - parent key not found