gpt4 book ai didi

grails - MySQLIntegrityConstraintException - Grails 中的 “Cannot add or update a child row: a foreign key constraint fails”

转载 作者:行者123 更新时间:2023-12-01 02:32:46 26 4
gpt4 key购买 nike

我试图从 XML 文件中获取一些订单信息并将其存储在数据库(MySQL)表中。我可以从 XML 文件中检索订单信息,但是当我尝试插入表时,它显示错误为 MySQLIntegrityConstraintException。

我的程序包含如下,
def Order = new XmlParser().parse("MyXml.xml")def set1 = sql.dataSet("order_item")def set2 = sql.dataSet("order_header")Order.order_item.each {// retrieving order information and storing}set1.add(Column_Name1:order_id,Column_Name2:field2,Column_Name3:field3)set2.add(Column_Name1:order_id)
我在下面详细列出了错误

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 (ecommerc
e/order_item
, CONSTRAINT ORDER_ITEM_HDR FOREIGN KEY (ORDER_ID) REFERENCES
order_header
(ORDER_ID)) Caught: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationExcepti on: Cannot add or update a child row: a foreign key constraint fails (ecommerce
/order_item
, CONSTRAINT ORDER_ITEM_HDR FOREIGN KEY (ORDER_ID) REFERENCES o
rder_header
(ORDER_ID)) com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cann ot add or update a child row: a foreign key constraint fails (ecommerce/order_i
tem
, CONSTRAINT ORDER_ITEM_HDR FOREIGN KEY (ORDER_ID) REFERENCES order_hea
der
(ORDER_ID)) 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)



谁能帮我解决这个问题。提前致谢

最佳答案

首先首先要更新的外键约束表然后是我应该更新的特定表。上面代码的一个小改动是
set2.add(Column_Name1:order_id)set1.add(Column_Name1:order_id,Column_Name2:field2,Column_Name3:field3)
应该先更新集合 2,然后再更新集合 1。

现在它对我有用了。谢谢大家。

关于grails - MySQLIntegrityConstraintException - Grails 中的 “Cannot add or update a child row: a foreign key constraint fails”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12086096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com