question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Foreign key constraint fails (jdbc, jpa, mysql)

See original GitHub issue

Hello

Maybe this is a configuration problem on my end, but I tried it based on the sample ‘lightmin-jpa-application’ as well. The following describes what I did with the lightmin-jpa-application (all in ApplicationConfiguration.java):

  1. Instead of a H2 in memory database, I changed the datasource(s) to
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
(...)
  1. Changed the database from H2 to Mysql:
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
  1. Added the jdbc configuration repository annotation:
@EnableLightminJdbcConfigurationRepository

Of course I had to add the respective dependencies in the pom.

After I created the required tables I was able to start the application just fine. However, when I try to add a new scheduler (cron) the operation fails with the following exception:

PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_CONFIGURATION_VALUE (job_configuration_id,value_key, configuration_value) VALUES (?,?,?)]; (conn=603) Cannot add or update a child row: a foreign key constraint fails (testlightmin.batch_job_configuration_value, CONSTRAINT batch_job_configuration_value_ibfk_1 FOREIGN KEY (job_configuration_id) REFERENCES batch_job_configuration (job_configuration_); nested exception is java.sql.BatchUpdateException: (conn=603) Cannot add or update a child row: a foreign key constraint fails (testlightmin.batch_job_configuration_value, CONSTRAINT batch_job_configuration_value_ibfk_1 FOREIGN KEY (job_configuration_id) REFERENCES batch_job_configuration (job_configuration_)

The autoincrement value on BATCH_JOB_CONFIGURATION.job_configuration_id does increase, but no record is ever stored. Could there be a problem with a transaction, or did I miss something?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tuxdevelopcommented, Jul 4, 2019

Hi, versions 1.0.2 and 2.0.2 are released and they are containing the fix.

0reactions
tuxdevelopcommented, Jun 12, 2019

Hi @kevinzogg, thank you very much. I will create a 2.0.2 release as soon as possible which includes the fix.

Greetings,

Marcel

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to solve foreign key constraint fails when inserting data
Ah I think I see the problem. Through the incorrect setup of the foreign key value fkcartid in Cartitem , the value of...
Read more >
java.sql.SQLException: Cannot add or update a child row
SQLException: Cannot add or update a child row: a foreign key constraint fails (`springmvc/businesslocation`, CONSTRAINT ... at com.mysql.jdbc.MysqlIO.
Read more >
13.1.18.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
A foreign key constraint on the base column of a stored generated column cannot use CASCADE , SET NULL , or SET DEFAULT...
Read more >
Foreign Key Constraint Fails - Appian Community
Hi, Foreign key should not be null while writing the data to the database. So please verify the value to which foreign key...
Read more >
[spring, jpa] Cannot add or update a child row: a foreign key ...
mysql 의 auto_increment(자동증가)를 기본키로 사용하고 있다. ... Cannot add or update a child row: a foreign key constraint fails (`dbName`.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found