• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Sever Error: Cannot update child

 
Greenhorn
Posts: 21
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could this be that the FK was not properly created when the DB/Table was created?
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic