ORA-02291: integrity constraint

1.3k Views Asked by At

I am having a hard time with ORA-02291: integrity constraint, I have a table (TF_MODE) which is linked to another table (PRODUCT) such that you can have a row in TF_MODE for various products. The problem is I can insert 10 rows perfectly in the TF_MODE table but the moment I try to insert the 11th row (i.e when the ID = 11) I get the "ORA-02291: integrity constraint" even though the foreign key does exist for the 11th entry in the PRODUCT table, the strange thing is the query is successful if I change the ID to let's say 12/14, but for some ID's it won't work e.g 999,1000 ; there is no fixed pattern for which it won't work, so basically the problem is specifically with the few ID values and not with the fact that for that foreign key the value don't exist in the parent table (actually the value does exist).

I am using Oracle 11g.

Any idea what could be the reason behind this strange behavior ?

Thanks !

Update:

There are no triggers, the only check constraints are 'IS NOT NULL'.

TFMODE:

CREATE TABLE "DESIGN"."TFMODE"
(
"ID"                NUMBER(38,0) NOT NULL ENABLE,
"F_PRODUCT"         NUMBER(38,0) NOT NULL ENABLE,
"SYS.CURRENT_I[MA]" NUMBER(10,3) NOT NULL ENABLE,
"LAST_MODIFIED_DATE" DATE NOT NULL ENABLE,
"VOLTAGE" NUMBER(10,3) NOT NULL ENABLE,
CONSTRAINT "TFMODE_PK" PRIMARY KEY ("ID") USING 
INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(
INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 
0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT 
CELL_FLASH_CACHE DEFAULT) TABLESPACE "DESIGN" ENABLE,
CONSTRAINT "TFMODE_PRODUCT_FK1" FOREIGN KEY ("ID") REFERENCES 
 "DESIGN"."PRODUCT" ("ID") ENABLE
) 

 SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 
NOCOMPRESS LOGGING STORAGE
(
INITIAL 81920 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0
FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT 
CELL_FLASH_CACHE DEFAULT
)
TABLESPACE "DESIGN" ;

PRODUCT:

CREATE TABLE "DESIGN"."PRODUCT"
(
"ID"           NUMBER(*,0) NOT NULL ENABLE,
"MANUFACTURER" VARCHAR2(100 BYTE),
...
)
TABLESPACE "DESIGN" ;

The PRODUCT table has lot's of columns and have been omitted for brevity.

Insert Statement (from java application):

INSERT INTO TFMODE VALUES  ( 11, 953, 2.27, to_date('2014-11-18','YYYY-MM-DD'), 3.8) 

I tried editing things from sql developer but same results, here's the screen shots:

ID=11 doesn't work

enter image description here

ID=12 works

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Check your Foreign key definition. Shouldn't it be

CONSTRAINT "TFMODE_PRODUCT_FK1" FOREIGN KEY ("F_PRODUCT") REFERENCES 
 "DESIGN"."PRODUCT" ("ID") ENABLE
) 

in the posted one you are linking two primary keys which doesn't make much sense