I have the following configurations for my Drupal site:
我的Drupal站点有以下配置:
sites/mysite/settings.local.php
站点/我的站点/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
对于drush,我有:drush/ites/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:
现在,当我运行drush@local.mysite cr时,我得到:
The specified database connection is not defined: default
If I run drush @local.mysite status
, I get:
如果我运行drush@local.mysite状态,我会得到:
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.
从这个错误中,我假设drush使用的是默认设置,而不是为我的站点指定的设置。但我已将相同的数据库配置添加到默认设置中,这不起作用。另外,我复制了settings.local.php,但它也给出了相同的错误。我是Drupal的新手,我正在开发的是一个现有的代码库。如果有人能帮助我正确地使用drush,这样我就可以设置我的本地开发环境,这将是非常有帮助的。
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
我已经尝试从命令行连接到数据库,它正在工作,我也能够从PHPMyAdmin访问数据库
更多回答
优秀答案推荐
Your sites/mysite/settings.local.php
should probably be named sites/mysite/settings.php
. Unless you already have a settings.php including your settings.local.php.
您的站点/MySite/settings.local.php可能应该命名为Sites/MySite/settings.php。除非您已经有一个包括settings.local.php的settings.php。
I also see you have it in a mysite
folder. Are you settings up a multisite drupal installation? Otherwise just put it in the default
folder.
我也看到你把它放在我的网站文件夹里了。您是否正在设置多站点Drupal安装?否则,只需将其放入默认文件夹。
Drupal by default loads settings.php
for a sites settings. This file than can optionally include a settings.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
默认情况下,Drupal为站点设置加载settings.php。此文件可以选择性地包含settings.local.php。查看源代码以了解它具体在哪里做这件事。您通常只有此settings.local.php文件用于特定于当前计算机的设置覆盖,并且通常不会将其提交到存储库
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.
我在执行drush命令时遇到了同样的问题。我的错误背后的原因是sites.php文件中缺少一个目录别名。例如:我有一个名为“Example.local.com”的站点,我创建了一个名为“Example”的站点文件夹。我不得不在sites.php文件中添加一个目录别名来解决这个问题。
$sites['example.local.com'] = 'example';
Hope this helps someone!!
希望这能帮助一些人!!
Refer: https://www.techpond.in/drush-specified-database-connection-not-defined-default
参考:https://www.techpond.in/drush-specified-database-connection-not-defined-default
更多回答
我是一名优秀的程序员,十分优秀!