I have a very easy table (id, name, parent) that represents a tree. I want to use dbunit while testing this table, so I created a simple dataset for 2 nodes (yaml instead of xml for readability):
我有一个非常简单的表(id,name,parent)代表一棵树。我想在测试这个表时使用dbunit,所以我为2个节点创建了一个简单的数据集(yaml而不是xml以便于阅读):
node:
- id: 1
name: default
parent: null
- id: 2
name: default-child
parent: 1
This gets inserted all right, but when trying to clean the table (I'm using DatabaseOperation.CLEAN_INSERT) it causes a constraint violation:
这可以插入,但在尝试清理表时(我正在使用DatabaseOperation.CLEAN_INSERT)会导致约束违规:
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (node, CONSTRAINT FK_NODE.PARENT_TO_NODE.ID FOREIGN KEY (parent) REFERENCES node (id))
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:无法删除或更新父行:外键约束失败(节点,CONSTRAINT FK_NODE.PARENT_TO_NODE.ID FOREIGN KEY(父)REFERENCES节点(id))
1 个解决方案
#1
2
i found a workaround: using truncate_table operation instead of gentle clean operation works for me on mysql
我发现了一个解决方法:在mysql上使用truncate_table操作而不是温和的清理操作
#1
2
i found a workaround: using truncate_table operation instead of gentle clean operation works for me on mysql
我发现了一个解决方法:在mysql上使用truncate_table操作而不是温和的清理操作