PHPUnit and MySQL truncation error(PHPUnit 和 MySQL 截断错误)
问题描述
I am getting a headache with PHPUnit's behavior of always running TRUNCATE
prior to inserting fixtures without first setting foreign key checks off:
Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint
Basically, PHPUnit tries to truncate a table before it inserts fixtures. How do I tell it to SET FOREIGN_KEY_CHECKS=0;
?
I found the answer it seems. I ended up overriding some methods by extending a class.
Then example usage:
So I'm effectively disabling foreign key checks and setting them back if they were ever set. Obviously you should make a base class that has this functionality and you extend it rather than PHPUnit's TestCase.
这篇关于PHPUnit 和 MySQL 截断错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!