I have the following configurations for my Drupal site:
sites/mysite/settings.local.php
$databases['default']['default'] = array(
'database' => 'mydb',
'username' => 'root',
'password' => 'password',
'prefix' => '',
'host' => '127.0.0.1',
'port' => '',
'namespace' => 'Drupal\Core\Database\Driver\mysql',
'driver' => 'mysql',
);
and for drush, I have :
drush/sites/local.site.yml
mysite:
root: /Users/me/Desktop/Work/Projects/mysite/docroot
uri: mysite.local
Now when I run drush @local.mysite cr
, I am getting:
The specified database connection is not defined: default
If I run drush @local.mysite status
, I get:
Drupal version : 9.5.9
Site URI : http://mysite.local
PHP binary : /usr/local/Cellar/[email protected]/8.1.19/bin/php
PHP config : /usr/local/etc/php/8.1/php.ini
PHP OS : Darwin
Drush script : /usr/local/bin/drush
Drush version : 10.6.1
Drush temp : /tmp
Drush configs : /Users/me/Desktop/Work/Projects/mysite/vendor/drush/drush/drush.yml
Drupal root : /Users/me/Desktop/Work/Projects/mysite/docroot
Site path : sites/default
From this error, I assume that Drush is using the default settings and not the one specified for my site. But I have added the same database configurations to the default settings, which is not working. Also, I have copied the settings.local.php
, but it also gives me the same error. I am new to Drupal, and it is an existing codebase that I am working on. It would be very helpful if someone could help me use Drush correctly so I can set up my local development environment.
I have tried to connect to database from the command line, and it is working and also I am able to access the database from PHPMyAdmin
2
Answers
Your
sites/mysite/settings.local.php
should probably be namedsites/mysite/settings.php
. Unless you already have a settings.php including your settings.local.php.I also see you have it in a
mysite
folder. Are you settings up a multisite drupal installation? Otherwise just put it in thedefault
folder.Drupal by default loads
settings.php
for a sites settings. This file than can optionally include asettings.local.php
.See The source for where it specifically does it.
You would only generally have this settings.local.php file for settings overrides specifically for the current machine and would usually not commit this to a repository
I had a same issue while executing a drush command. The reason behind my error was a missing directory alias in sites.php file. For ex: I had a site with "example.local.com" and I had created a site folder with the name "example". I had to add a directory alias in sites.php file to fix the issue.
Hope this helps someone!!
Refer: https://www.techpond.in/drush-specified-database-connection-not-defined-default