php - 警告 : Fixture creation for "catalog_items" failed "SQLSTATE[42S01]

标签 php mysql phpunit cakephp-3.0 fixtures

这是我遇到的错误。让我知道其根本原因是什么。

SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (Proficiency.t_catalog_item_recommendations, CONSTRAINT fk_t_catalog_item_recommendations_catalog_item_id FOREIGN KEY (catalog_item_id) REFERENCES Proficiency.t_catalog_items (id))

每当我执行测试脚本时,它都会给出以下消息:

Warning: Fixture creation for "catalog_items" failed "SQLSTATE[42S01]: Base table or view already exists: 1050 Table 't_catalog_items' already exists" in /var/www/html/lib/Cake/TestSuite/Fixture/CakeTestFixture.php on line 244 Call Stack: 0.0018 262208 1. {main}() /var/www/html/app/webroot/test.php:0 0.1119 1133560 2. CakeTestSuiteDispatcher::run() /var/www/html/app/webroot/test.php:97 0.1120 1133968 3. CakeTestSuiteDispatcher->dispatch() /var/www/html/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:113 0.1205 1278304 4. CakeTestSuiteDispatcher->_runTestCase() /var/www/html/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:96 0.1314 1320376 5. CakeTestSuiteCommand->run() /var/www/html/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php:253 0.1930 2144664 6. CakeTestRunner->doRun() /var/www/html/lib/Cake/TestSuite/CakeTestSuiteCommand.php:96 0.2285 2481368 7. PHPUnit_TextUI_TestRunner->doRun() /var/www/html/lib/Cake/TestSuite/CakeTestRunner.php:60 0.2334 2521736 8. PHPUnit_Framework_TestSuite->run() /var/www/html/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:350 0.2538 2770160 9. PHPUnit_Framework_TestSuite->runTest() /var/www/html/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:749 0.2538 2770288 10. CakeTestCase->run() /var/www/html/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:779 0.2538 2770512 11. CakeFixtureManager->load() /var/www/html/lib/Cake/TestSuite/CakeTestCase.php:80 0.2541 2772984 12. CakeFixtureManager->_setupTable() /var/www/html/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php:234 0.2572 2784752 13. CakeTestFixture->create() /var/www/html/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php:206 0.4597 2824904 14. trigger_error() /var/www/html/lib/Cake/TestSuite/Fixture/CakeTestFixture.php:244

最佳答案

The documentation说:

TRUNCATE cannot be used on a table that has foreign-key references from other tables, unless all such tables are also truncated in the same command.

所以这就是你必须做的。

关于php - 警告 : Fixture creation for "catalog_items" failed "SQLSTATE[42S01],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907254/

相关文章:

mysql - 在子查询中使用别名

MySQL 在多个 UNION 后使用 GROUP BY

php - PHPUnit 测试需要在 "/test"目录中吗?

php - 在 PHPUnit 中测试工作链接

javascript - 如何使用 AJAX 从 PHP 访问字符串到 jQuery

用于表单密集型应用程序的 PHP 框架

php - 好的PHP文本分页

mysql - 调整只写主 mysql 数据库

php - 您如何管理项目中的单元测试文件?你在git中添加它们吗?

php - 为 MySQL 编写的 PDO 脚本是否应该与 Oracle 一起使用?