0
我已經通過google/stackoverflow搜索解決方案,但未能找到令人滿意的解決方案。(kohana)單元測試DbUnit外鍵約束
我的問題:
[SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a
foreign key constraint (integration.b_node_leafs, CONSTRAINT fk_node_id
FOREIGN KEY (node_id) REFERENCES integration.b_nodes (id))]
我不能誰解決這一問題的既不是爲了XmlDataSet(我使用)的訂單,該文檔的任何地方找到。
這不起作用。
public function setUp() {
$conn=$this->getConnection();
$conn->getConnection()->query("set foreign_key_checks=0");
parent::setUp();
$conn->getConnection()->query("set foreign_key_checks=1");
}
結果mysql.log
Connect [email protected] on integration_db
Query set foreign_key_checks=0
Connect [email protected] on integration_db
Query TRUNCATE `table_name`
Quit
Quit
這是我dataset.xml(正如你看到的我是從底部開始)。
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<!-- Meta for node -->
<b_meta id="4321" created_by="###NULL###" deleted="0" />
<!-- Meta for leaf -->
<b_meta id="1010" created_by="###NULL###" deleted="0" />
<!-- Meta for post -->
<b_meta id="1050" created_by="###NULL###" deleted="0" />
<!-- meta for comment -->
<b_meta id="7894" created_by="###NULL###" deleted="0" />
<!-- Add comment -->
<b_comments id="5555" meta_id="7894" text="This is a integrationtest" />
<!-- Add Post -->
<b_posts id="4646" meta_id="1050" title="How to integration" seo_title="how-to-integration" text="Explain why to use integrationtests" />
<!-- Link comment to post -->
<b_post_comments post_id="4646" comment_id="5555" />
<!-- Add Leaf -->
<b_leafs id="3535" meta_id="1010" title="App Testing" seo_title="app-testing" />
<!-- Link leaf to post -->
<b_leaf_posts leaf_id="3535" post_id="4646" />
<!-- Add node -->
<b_nodes id="1234" meta_id="4321" type="forum" title="PHP" />
<!-- Link node to leaf -->
<b_node_leafs node_id="1234" leaf_id="3535" />
</dataset>
PS:我在PHPUnit的28年3月7日
這是一個MySQL的限制,你只能通過刪除解決並重新據我所知創建外鍵。 –