这是我遇到的错误。让我知道其根本原因是什么。
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table referenced in a foreign key constraint (
Proficiency
.t_catalog_item_recommendations
, CONSTRAINTfk_t_catalog_item_recommendations_catalog_item_id
FOREIGN KEY (catalog_item_id
) REFERENCESProficiency
.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
最佳答案
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/