为什么 CakePHP 无法为一个控制器和 returns SQLSTATE[42000] 创建固定装置,而它是为另一个控制器创建的?

Why is CakePHP unable to create fixtures for one controller and returns SQLSTATE[42000] while it is for another controller?

我的 Cake 快线PHP申请(重要部分):

我有一个用户 table 拥有所需的一切(模型、控制器、视图、夹具、测试用例)。 在其他数据中,该用户 table 引用了一个城市 Table、一个国家和一条街道 table。 对于城市、国家和街道,一切都在那里并且有效:(模型、控制器、视图、夹具、测试用例)。

Fixtrue 和 Text Case 是用 Bake 构建的。

虽然我可以 运行 城市、国家和街道的测试用例,但我不能 运行 用户的测试用例,因为我收到此错误消息:

Exception: Unable to create constraints for fixture "App\Test\Fixture\UsersFixture" in "App\Test\TestCase\Controller\UsersControllerTest" test case: 
SQLSTATE[42000]: Syntax error or access violation: 1142 REFERENCES command denied to user 'cake_user'@'localhost' for table 'cities'
In [/opt/git/premesec/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 335]

令我困惑的是,当我 运行 城市 TestCases 时,我可以 运行 城市的固定装置,但是当相同的固定装置应该 运行 用于用户时出现问题测试用例。

这里是约束形式 UsersFixtures.php:

'_constraints' => [
            'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
            'city_id' => ['type' => 'foreign', 'columns' => ['city_id'], 'references' => ['cities', 'id'], 'update' => 'noAction', 'delete' => 'noAction', 'length' => []],
            'fk_country_id' => ['type' => 'foreign', 'columns' => ['country_id'], 'references' => ['countries', 'id'], 'update' => 'noAction', 'delete' => 'noAction', 'length' => []],
            'house_number_id' => ['type' => 'foreign', 'columns' => ['house_number_id'], 'references' => ['house_numbers', 'id'], 'update' => 'noAction', 'delete' => 'noAction', 'length' => []],
            'street_id' => ['type' => 'foreign', 'columns' => ['street_id'], 'references' => ['streets', 'id'], 'update' => 'noAction', 'delete' => 'noAction', 'length' => []],
        ],

这里是约束形式 CitiesFixtures.php:

'_constraints' => [
            'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []],
        ],

蛋糕PHP v4.0.6

PHP-版本:7.2.24

mysql 版本 14.14 分发 5.7.31,用于 Linux (x86_64)

仔细检查错误消息,这并不是关于 cities table,而是关于 REFERENCES 命令,您的帐户不允许 运行 ,即它是你的 Users 夹具中的外键约束,它很可能不会参与你的其他测试,即你的其他测试没有加载 Users 夹具。

长话短说,您需要相应地授予您的 cake_user 帐户 REFERENCES 权限,这是能够创建外键约束所必需的,或者选择一个已经存在的不同用户帐户具有所需的权限。

另见