Score:0

The specified database connection is not defined: default for Drupal drush

bh flag

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

leymannx avatar
ne flag
And when you run just `drush cr`? You don't need a Drush yaml for your local site. And are you able to access the site in the browser?
Happy Coder avatar
bh flag
It shows `The provided host name is not valid for this server` when I access the site in a browser. I have configured the `trusted_host_patterns` to `array( '^ mysite\.local$' )`, but still, the error persists.
Happy Coder avatar
bh flag
It also seems like it is pointing to the wrong folder altogether. The Apache configuration and virtual hosts are correct, but now I get error from another folder, which contains another Drupal site
id flag
Have you not configured sites.php? You are using multi site by not using sites/default. I’m not sure if that’s intentional. Is there a settings.php in sites/mysite? Does it include settings.local.php? You are doing some unusual things.
Score:1
cm flag

I assume that the reason you get

The specified database connection is not defined: default

is because sites/mysite/settings.local.php isn't included by any settings.php file.

Look for example at the end of sites/default/settings.php (or sites/default/default.settings.php) to see how the local settings are normally loaded.

id flag
This cannot be the only reason. They put that file in `sites/mysite` not `sites/default`.
cm flag
I don't disagree, but both you and I know that the name (and folder) for the local settings file is complete arbitrary as long the file actually is included from the used `settings.php` file ;-)
Ivaylo Tsandev avatar
us flag
I agree, not loading the `settings.local.php` in the main `settings.php` seems the most likely reason here
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.