bakeコマンド実行時にエラーが発生する場合

cake bake コマンド実行時にエラーが発生する場合

エラーメッセージ

[hoge@sv8069 app]$ ./bin/cake bake model

Welcome to CakePHP v3.1.14 Console
---------------------------------------------------------------
App : src
Path: /home/hogehoge/hogehoge.com/public_html/apl/app/src/
PHP : 5.4.16
---------------------------------------------------------------
Choose a model to bake from the following:
Exception: SQLSTATE[28000] [1045] Access denied for user 'hogehoge_test'@'localhost' (using password: YES) in [/home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php, line 48]
2019-08-05 00:55:47 Error: [PDOException] SQLSTATE[28000] [1045] Access denied for user 'hogehoge_test'@'localhost' (using password: YES)
Stack Trace:
#0 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php(48): PDO->__construct('mysql:host=loca...', 'hogehoge_test', 'pass1234', Array)
#1 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php(90): Cake\Database\Driver\Mysql->_connect('mysql:host=loca...', Array)
#2 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Schema/BaseSchema.php(45): Cake\Database\Driver\Mysql->connect()
#3 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Dialect/MysqlDialectTrait.php(63): Cake\Database\Schema\BaseSchema->__construct(Object(Cake\Database\Driver\Mysql))
#4 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Schema/Collection.php(52): Cake\Database\Driver\Mysql->schemaDialect()
#5 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Schema/CachedCollection.php(43): Cake\Database\Schema\Collection->__construct(Object(Cake\Database\Connection))
#6 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Database/Connection.php(315): Cake\Database\Schema\CachedCollection->__construct(Object(Cake\Database\Connection), true)
#7 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(919): Cake\Database\Connection->schemaCollection()
#8 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(874): Bake\Shell\Task\ModelTask->_getAllTables()
#9 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(888): Bake\Shell\Task\ModelTask->listAll()
#10 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/bake/src/Shell/Task/ModelTask.php(90): Bake\Shell\Task\ModelTask->listUnskipped()
#11 [internal function]: Bake\Shell\Task\ModelTask->main()
#12 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Console/Shell.php(455): call_user_func_array(Array, Array)
#13 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Console/Shell.php(449): Cake\Console\Shell->runCommand(Array, false)
#14 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(212): Cake\Console\Shell->runCommand(Array, true, Array)
#15 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(179): Cake\Console\ShellDispatcher->_dispatch(Array)
#16 /home/hogehoge/hogehoge.com/public_html/apl/app/vendor/cakephp/cakephp/src/Console/ShellDispatcher.php(126): Cake\Console\ShellDispatcher->dispatch(Array)
#17 /home/hogehoge/hogehoge.com/public_html/apl/app/bin/cake.php(33): Cake\Console\ShellDispatcher::run(Array)
#18 {main}

[hogehoge@sv8069 app]$

対応方法

下記のファイルで、Datasourcesの接続情報が間違っている可能性が高いので、下記の項目を見直します。

app/config/app.php
'host' => 'xxxxxxx.xserver.jp',
'username' => 'hosehoge_test',
'password' => 'pass1234',
'database' => 'hogehoge_app',
'encoding' => 'utf8',

また、dafult 以外に、test についても同様の設定項目があるので、見直すと良いと思います。

スポンサーリンク