I am receiving the error below when running the below sql statements on very simple tables. the only foreign key used here is in the table runs
and the foreign key is runs.sample_id
which references samples.id
. I'm not sure why I am receiving this error as I am trying to delete all the runs before deleting the samples in which they depend on. Code below:
java code:
String deleteRunsQuery = "DELETE FROM runs"; //delete rows from runs table String deleteSamplesQuery = "DELETE FROM samples"; //delete rows from samples table
stmt.executeUpdate(deleteRunsQuery);
stmt.executeUpdate(deleteSamplesQuery);
and the exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (gc_image_relational
.runs
, CONSTRAINT runs_ibfk_1
FOREIGN KEY (sample_id
) REFERENCES samples
(id
))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2541)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1604)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1535)
at com.gcimage.relational.RelationalDatabaseTest.disposeDb(RelationalDatabaseTest.java:40)