com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`grades_book_db`.`grades`, CONSTRAINT `FK_Grades_Subject` FOREIGN KEY (`Subject_Id`) REFERENCES `subjects` (`Subject_Id`))

tip
Click on the to mark the solution that helps you, Samebug will learn from it.
As a community member, you’ll be rewarded for you help.
  1. 0

    'Cannot add or update a child row: a foreign key constraint fails' when trying to add a primary composite key in Hibernate

    Stack Overflow | 2 weeks ago | Mykhailo Seniutovych
    com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`grades_book_db`.`grades`, CONSTRAINT `FK_Grades_Subject` FOREIGN KEY (`Subject_Id`) REFERENCES `subjects` (`Subject_Id`))
  2. 0

    CONSTRAINT `FK278CE8101186666B` Exception

    https://bugzilla.redhat.com/bugzilla/ | 3 years ago | Dennis Crissman
    com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`candlepin`.`cp_consumer_facts`, CONSTRAINT `FK278CE8101186666B` FOREIGN KEY (`cp_consumer_id`) REFERENCES `cp_consumer` (`id`))
  3. 0

    problem with foreign key in populating database

    Stack Overflow | 6 years ago
    com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cann ot add or update a child row: a foreign key constraint fails (`cs585hw3`.`reserv ations`, CONSTRAINT `reservations_ibfk_1` FOREIGN KEY (`flight_no`) REFERENCES ` flights` (`flight_no`))
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Mysql Update

    GitHub | 3 months ago | Naghtrion
    java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails (`mc_151`.`mh_Daily`, CONSTRAINT `mh_Daily_Player_Id` FOREIGN KEY (`PLAYER_ID`) REFERENCES `mh_PlayersV2` (`PLAYER_ID`) ON DELETE CASCADE)
  6. 0

    Problemas de merge entre entidades: Teste Automatizado - Curso JEE e JSE – Loja Virtual Completa – Parte 25

    com.br | 1 year ago
    com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`devmedia`.`produto`, CONSTRAINT `FK_PRODUTO_CATEGORIA_id` FOREIGN KEY (`CATEGORIA_id`) REFERENCES `categoria` (`id`)) Error Code: 1451 Call: DELETE FROM CATEGORIA WHERE (id = ?) bind => [1 parameter bound] Query: DeleteObjectQuery(br.com.deyvison.entidades.Categoria[id=1])

  1. mauritius 2 times, last 4 months ago
  2. dafman 6 times, last 5 months ago
  3. davidvanlaatum 6 times, last 5 months ago
  4. tvrmsmith 1 times, last 7 months ago
  5. DoktorDoener666 7 times, last 4 weeks ago
9 more registered users
45 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

    Cannot add or update a child row: a foreign key constraint fails (`grades_book_db`.`grades`, CONSTRAINT `FK_Grades_Subject` FOREIGN KEY (`Subject_Id`) REFERENCES `subjects` (`Subject_Id`))

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0()
  2. Java RT
    Constructor.newInstance
    1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    2. sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    4. java.lang.reflect.Constructor.newInstance(Unknown Source)
    4 frames
  3. MySQL jdbc
    PreparedStatement.executeUpdate
    1. com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    2. com.mysql.jdbc.Util.getInstance(Util.java:408)
    3. com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
    4. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
    5. com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
    6. com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
    7. com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
    8. com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
    9. com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    10. com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
    11. com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
    12. com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
    13. com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
    13 frames
  4. Hibernate
    ResultSetReturnImpl.executeUpdate
    1. org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
    1 frame