简体   繁体   中英

CakePHP - cake bake all error (says missing $default in database.php, but it is present)

I am trying to bake all with cake bake all, but it returns all sorts of errors. It says that default in database.php cannot be found, but in reality it is present in the file, also, few days ago I baked few models etc and it worked fine. Here is the output:

C:\wamp64\www\WarehouseManagementApp\app\Console>cake bake all

Warning Error: Use of undefined constant TESTS - assumed ‘TESTS’ (this will throw an Error in a future version of PHP) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\TaskCollection.php, line 94]
Welcome to CakePHP v2.10.19 Console
App : Console
Path: C:\wamp64\www\WarehouseManagementApp\app\Console\
Bake All

Warning Error: include_once(C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php): failed to open stream: No such file or directory in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]

Warning Error: include_once(): Failed opening ‘C:\wamp64\www\WarehouseManagementApp\app\Console\Config\database.php’ for inclusion (include_path=‘C:\wamp64\www\WarehouseManagementApp\lib;.;C:\php\pear’) in [C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php, line 67]

Error: The datasource configuration “default” was not found in database.php
#0 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Model\ConnectionManager.php(91): ConnectionManager::_getConnectionObject(‘default’)
#1 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(956): ConnectionManager::getDataSource(‘default’)
#2 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(893): ModelTask->getAllTables(‘default’)
#3 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\Task\ModelTask.php(983): ModelTask->listAll(‘default’)
#4 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Command\BakeShell.php(150): ModelTask->getName(‘default’)
#5 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\Shell.php(459): BakeShell->all()
#6 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(222): Shell->runCommand(‘all’, Array)
#7 C:\wamp64\www\WarehouseManagementApp\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()
#8 C:\wamp64\www\WarehouseManagementApp\app\Console\cake.php(47): ShellDispatcher::run(Array)
#9 {main}

Also, here is my database.php file:

class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => '',
    'database' => 'modules',
    'prefix' => '',

// ‘encoding’ => ‘utf8’,
);

public $test = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'user',
    'password' => 'password',
    'database' => 'test_database_name',
    'prefix' => '',
    //'encoding' => 'utf8',
);

}

Look at the include errors, they tell you that your database.php file cannot be found, and if you look at the path, you see that it looks in the Console/Config folder, which is of course the wrong location.

That is because the shell will use the current working directory as the application path, so either run the console from within your app folder, ie Console\cake bake all , or use the -app parameter to pass the path to your app folder:

cake bake all -app "C:\wamp64\www\WarehouseManagementApp\app"

The cake shell tells you about that too ( cake --help ), and shows you the relevant paths.

See also

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM