views:

10

answers:

1

I have structure table like this.

alt text

the problem is :

When i want to input data to "index" table. I got this error.

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (test.index, CONSTRAINT index_ibfk_5 FOREIGN KEY (b_FK) REFERENCES b (Id_B))

When i remove the relation index and b. it's working fine.

i using same way for a_Fk, and c_Fk. but only b_FK which have problem.

Anyone know how to solve this? thx b4

FYI : i using java, net bean 6.8, mySql (Xampp V.3.2.0.1)

A: 

You are inserting a value in column b_FK of table index that does not exist in table b, Id_B column.

Perhaps you should make sure to insert data in tables a, b, and c and only then in index. Also, if your b_FK column is something like not null default 0, change it to accept null for whenever you need to save a row to index table with an empty b_FK.

As extraneon said in his comment, it always help to provide more data, we can't guess these details ourselves.

ceteras