• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
raj chopra
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic