Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQLIntegrityConstraintException - “Cannot add or update a child row: a foreign key constraint fails” in Grails
    text
    copied!<p>Am trying to get some order information from XML file and trying to store it in database(MySQL) table. I can retrieve the order information from XML file but when am trying to insert into the table it shows error as MySQLIntegrityConstraintException.</p> <p>My program contains as below,</p> <p><code>def Order = new XmlParser().parse("MyXml.xml")</code><br> <code>def set1 = sql.dataSet("order_item")</code><br> <code>def set2 = sql.dataSet("order_header")</code><br> <code>Order.order_item.each {</code><br> <code>// retrieving order information and storing</code><br> <code>}</code><br> <code>set1.add(Column_Name1:order_id,Column_Name2:field2,Column_Name3:field3)</code><br> <code>set2.add(Column_Name1:order_id)</code> </p> <p>I listed the error in detail below</p> <blockquote> <p>WARNING: Failed to execute: insert into order_item (order_id, order_item_seq_id, order_item_type_id, product_id, prod_catalog_id, quantity, unit_price, unit_lis t_price, item_description, status_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) beca use: Cannot add or update a child row: a foreign key constraint fails (<code>ecommerc e/order_item</code>, CONSTRAINT <code>ORDER_ITEM_HDR</code> FOREIGN KEY (<code>ORDER_ID</code>) REFERENCES <code> order_header</code> (<code>ORDER_ID</code>)) Caught: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationExcepti on: Cannot add or update a child row: a foreign key constraint fails (<code>ecommerce /order_item</code>, CONSTRAINT <code>ORDER_ITEM_HDR</code> FOREIGN KEY (<code>ORDER_ID</code>) REFERENCES <code>o rder_header</code> (<code>ORDER_ID</code>)) com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cann ot add or update a child row: a foreign key constraint fails (<code>ecommerce/order_i tem</code>, CONSTRAINT <code>ORDER_ITEM_HDR</code> FOREIGN KEY (<code>ORDER_ID</code>) REFERENCES <code>order_hea der</code> (<code>ORDER_ID</code>)) at com.mysql.jdbc.Util.handleNewInstance(Util.java:409) at com.mysql.jdbc.Util.getInstance(Util.java:384) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.ja va:2105) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :2398) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :2316) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java :2301) at db2xml.XMLToDatabase$_main_closure2.doCall(XMLToDatabase.groovy:52) at db2xml.XMLToDatabase.main(XMLToDatabase.groovy:38) </p> </blockquote> <p>Can anyone help me to come out from this problem. Thanks in advance </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload