473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MySQLIntegrityConstraintViolationException

snowfall
I am getting the following error on inserting into my MySQL DBase.

My child table has a foreign key of the parent table. But while creating the table, i have used 'on delete cascade'.

I dnt know what the problem is. Pls help

com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Cannot add
or update a child row: a foreign key constraint fails
Jan 10 '08 #1
6 16225
debasisdas
8,127 Expert 4TB
This error occurs when you try to insert a duplicate value into a primay key or Unique constrained field.

Check to ensure that the value does not exist in database before inserting.
Jan 10 '08 #2
This error occurs when you try to insert a duplicate value into a primay key or Unique constrained field.

Check to ensure that the value does not exist in database before inserting.
But i dnt have a primary key or unique key in my table. I have only Foreign Key

My table structure is

+---------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| reply_no | int(5) | YES | | NULL | |
| question_no | int(5) | YES | MUL | NULL | |
| reply_content | text | YES | | NULL | |
| emp_name | varchar(40)| YES | | NULL | |
| emp_no | int(6) | YES | | NULL | |
| entry_dat | date | YES | | NULL | |
+---------------+-------------+------+-----+---------+-------+

pls help
Jan 10 '08 #3
rpnew
188 100+
I am getting the following error on inserting into my MySQL DBase.

My child table has a foreign key of the parent table. But while creating the table, i have used 'on delete cascade'.

I dnt know what the problem is. Pls help

com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Cannot add
or update a child row: a foreign key constraint fails
This error occurs when you are entering data into child table which is not there into parent table.

e.g.
I've PARENT table and CHILD table both contains one field say NAME.
Now NAME in CHILD is a foreign key which refers to the NAME in PARENT.
So if i insert anything in CHILD table's NAME field which is not there in PARENT table's NAME field than it will show this error. That is what foreign key constraint is there for.
To make it more clear lets take example with values...

Say Parent table contains two entries for NAME one is 'abc' and another is 'xyz'. So, if i'll try to insert anything besides these two values into child table's NAME column it will give me above mentioned error.

Regards,
RP
Jan 10 '08 #4
If i delete a row in the child table with 'where condition of my foreign key', then does the table get corrupt??

Is that why i am getting this error??
Jan 14 '08 #5
rpnew
188 100+
If i delete a row in the child table with 'where condition of my foreign key', then does the table get corrupt??

Is that why i am getting this error??
hi,
Are you deleting or adding(updating)...
cause this error comes when you are adding or updating child table column which has foreign key reference.

Regards,
RP
Jan 14 '08 #6
debasisdas
8,127 Expert 4TB
on delete cascade specifies if the parent data is deleted its dependent child record will also be deleted from the child table.

and the foreign key ensures that the parent record can't be deleted while there are some dependent child records in the child table.
Jan 16 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nickyeng | last post by:
imageValue=null SEVERE:--> com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'Gout_msgtext' cannot be null at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.