Heroku | The datasource configuration “default” was not found in database.php

| By Webner

Heroku throwing ERROR: “The datasource configuration “default” was not found in database.php” with database configuration already present for cakephp app.

In one of our cakephp projects hosted on Heroku we used PostgreSql database. For configuring the database to connect to app code we renamed the database.php.default file as database.php and then provided database configuration details in this file as follows:

$url = parse_url(getenv('DATABASE_URL'));

The above code works fine if we are performing database operation using app url and front-end. But if we try to perform any DML operation using cakephp command line, the above database configuration threw the error as:

“The data source configuration “default” was not found in database.php”.

while we’re using the command line, the code was not able to fetch db details from url and so the database settings were empty.

To resolve this we can use the database details for a Heroku app and provide these details in database.php itself rather than fetching the details from URL. For example, we can use the code as below:

public $default = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => 'Host Name’',
'login' => ''
databaseUserName ',
'password' => 'databasePassword',
'database' => 'databaseName',
'prefix' => '',
'encoding' => 'utf8',

The above details related to a Heroku app database can be fetched by logging into Heroku dashboard and then using the “Databases” link.

Leave a Reply

Your email address will not be published. Required fields are marked *