PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 12, 2022

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

 February 12, 2022     cakephp, cakephp-2.3, php     No comments   

Issue

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',
);

}

Solution

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

  • Cookbook > Shells, Tasks & Console Tools


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing