• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sever Error: Cannot update child

 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to store data to from a registration form (html). everything runs smoothly until I try to store the the Foreign Keys. When I test the form I get the following error:

SEVERE: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`ebooksalesdb_schema`.`user`, CONSTRAINT `fk_user_account_type1` FOREIGN KEY (`account_type_account_name`) REFERENCES `account_type` (`account_name`) ON DELETE NO ACTION ON UPDATE NO ACTION)

After running the application the stack trace indicates that the error is located at:
at eBooks.data.UserDB.insert(UserDB.java:47)
at eBooks.controller.RegisterUserServlet.doPost(RegisterUserServlet.java:71)



This is the code for the RegisterUserServlet:



This is the code for the UserDB class:
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luis Villamil wrote:CONSTRAINT `fk_user_account_type1` FOREIGN KEY (`account_type_account_name`) REFERENCES `account_type` (`account_name`)

That part means that each value that you put into the account_type_account_name column of this table, must have a matching value in the account_name column of the account_type table. Make sure that's the case.
 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could this be that the FK was not properly created when the DB/Table was created?
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luis Villamil wrote:Could this be that the FK was not properly created when the DB/Table was created?


quite likely, we have given you the name and the contents of the index, go and investigate your database see if that is what was wanted on it.
 
Luis Villamarin
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I worked on the database and effectively there was a relationship that was not correctly set. However, what I did, didn't fully fixed the problem this what I'm getting now as an error:


SEVERE: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`ebooksalesdb_schema`.`user`, CONSTRAINT `fk_user_account1` FOREIGN KEY (`account_account_id`, `account_account_type_account_name`) REFERENCES `account` (`account_id`, `account_type_account_na)

I noticed that at the end of the error it says `account_type_account_na, instead of `account_type_account_name'). I checked for the name inconsistency and couldn't find anywhere that `account_type_account_na. Could this be the reason ?


I rebuilt the database and I'm still getting the same error.

Do you have idea why this keeps on happening?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic