Drush - The specified database connection is not defined: default

Submitted by sysop on Sun, 09/10/2023 - 09:51

The specified database connection is not defined: default


The specified database connection is not defined

The error "The specified database connection is not defined: default" might arise when you use drupal multi-site environment and you have missed a directory aliasing entry in sites.php file. This error might also arise when a 'sites.php' file is missing.

The file 'sites.php' is required for multi-site support and also allows you to define a set of aliases that map hostnames, ports, and pathnames to configuration directories in the sites directory. These aliases are loaded prior to scanning for directories, and they are exempt from the normal discovery rules. Aliases are useful on development servers, where the domain name may not beĀ  the same as the domain of the live server. Since Drupal stores file paths in the database (files, system table, etc.) this will ensure the paths are correct when the site is deployed to a live server.

To fix the error "The specified database connection is not defined: default" follow the below steps:

Step1: Go to the "sites" directory within your drupal installation and copy and rename the example.sites.php file such that its path plus filename is 'sites/sites.php'.

cp example.sites.php sites.php

Step2: Then add a directory aliasing in sites.php file. For example, if you have created a directory like "example" for the domain "example.local.com", then add below alias in sites.php file.

$sites['example.local.com'] = 'example';

Step3: Now rebuild the registry.

drush cr

That should fix the error. Hope this documentation helps.