Answers.Body: <p>It looks like you’re specifying a <code>DB_DSN</code> in your <code>config/db.php</code> file, but your <code>.env</code> file isn’t defining that variable.</p>
  <p>You either need to specify the full <code>DB_DSN</code> string in your <code>.env</code> file or update your <code>config/db.php</code> file to pull in the individual database connection settings from your <code>.env</code> file.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-18T21:18:00.323Z
Answers.Text: Yup, that was it. For some reason updating `db.php` to use `DB_SERVER` didn't work but adding `DB_DSN="mysql:host=db;port=3306;dbname=db;"` to `.env` did.
Answers.UserDisplayName: kmgdev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-10-18T04:30:05.743Z
Answers.LastActivityDate: 2023-10-18T04:30:05.743Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've hit a snag while trying to move my Craft 3 project from MAMP to DDEV. First I installed a new DDEV project using the <code>php</code> project type and MySQL 8.0 for the database. Then I imported the database to DDEV. Then I updated my <code>.env</code> variables with the following values:</p>
  <pre><code>DB_DRIVER=&quot;mysql&quot;
  DB_SERVER=&quot;db&quot;
  DB_PORT=&quot;3306&quot;
  DB_DATABASE=&quot;db&quot;
  DB_USER=&quot;db&quot;
  DB_PASSWORD=&quot;db&quot;
  DB_SCHEMA=public
  DB_TABLE_PREFIX=
  </code></pre>
  <p>After that I launched the project in the browser, navigated to the control panel, and got hit with this error:</p>
  <blockquote>
  <p>No database has been selected yet.</p>
  </blockquote>
  <p>I was able to successfully connect to the database using a plain PHP test script, but Craft can't for some reason.</p>
  <p>Aside from checking and re-checking the <code>.env</code> settings I'm not exactly sure how else to troubleshoot this. The fact that Craft seems to think this is an installation issue is probably a clue, though I'm not really sure how.</p>
  <p>I ran <code>php craft setup/db-creds</code> and here's what I got back:</p>
  <pre><code>Which database driver are you using? (mysql or pgsql) [mysql] 
  Database server name or IP address: [db] 
  Database port: [3306] 
  Database username: [db] 
  Use the password provided by $DB_PASSWORD? (yes|no) [yes]:no
  Database password: 
  Database name: [db] 
  Database table prefix: 
  Testing database credentials ... failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
  </code></pre>
  <p>Here's what my <code>config/db.php</code> file looks like:</p>
  <pre><code>return [
      'dsn' =&gt; getenv('DB_DSN'),
      'user' =&gt; getenv('DB_USER'),
      'password' =&gt; getenv('DB_PASSWORD'),
      'schema' =&gt; getenv('DB_SCHEMA'),
      'tablePrefix' =&gt; getenv('DB_TABLE_PREFIX'),
  ];
  </code></pre>
  <p>Here's my <code>ddev describe</code> output:</p>
  <pre><code>┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Project: my-project ~/My/Project/Location/my-project https://my-project.ddev.site  │
  │ Docker platform: docker-desktop                                                                   │
  │ Router: traefik                                                                                   │
  ├──────────┬──────┬──────────────────────────────────────────────────────────┬──────────────────────┤
  │ SERVICE  │ STAT │ URL/PORT                                                 │ INFO                 │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ web      │ OK   │ https://my-project.ddev.site                        │ php PHP8.1           │
  │          │      │ InDocker: web:443,80,8025                                │ nginx-fpm            │
  │          │      │ Host: 127.0.0.1:55134,55133                              │ docroot:'dist'       │
  │          │      │                                                          │ Mutagen enabled (ok) │
  │          │      │                                                          │ NodeJS:18            │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ db       │ OK   │ InDocker: db:3306                                        │ mysql:8.0            │
  │          │      │ Host: 127.0.0.1:55132                                    │ User/Pass: 'db/db'   │
  │          │      │                                                          │ or 'root/root'       │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ Mailpit  │      │ Mailpit: https://my-project.ddev.site:8026          │                      │
  │          │      │ `ddev launch -m`                                         │                      │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ All URLs │      │ https://my-project.ddev.site,                       │                      │
  │          │      │ https://127.0.0.1:55134,                                 │                      │
  │          │      │ http://my-project.ddev.site, http://127.0.0.1:55133 │                      │
  └──────────┴──────┴──────────────────────────────────────────────────────────┴──────────────────────┘
  </code></pre>
  <p>Here's the full Craft error log:</p>
  <pre><code>yii\base\InvalidConfigException: No database has been selected yet. in /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php:320
  Stack trace:
  #0 /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php(73): craft\controllers\InstallController-&gt;_checkDbConfig()
  #1 [internal function]: craft\controllers\InstallController-&gt;actionIndex()
  #2 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #3 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction-&gt;runWithParams(Array)
  #4 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller-&gt;runAction('index', Array)
  #5 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(295): yii\base\Module-&gt;runAction('install/index', Array)
  #6 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(562): craft\web\Application-&gt;runAction('install/index')
  #7 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(203): craft\web\Application-&gt;_processInstallRequest(Object(craft\web\Request))
  #8 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
  #9 /var/www/html/dist/index.php(21): yii\base\Application-&gt;run()
  #10 {main}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-17T16:24:36.797Z
Comments.Text: What does your `config/db.php` file look like?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-10-17T17:38:46.467Z
Comments.Text: Edited the question to include it.
Comments.UserDisplayName: kmgdev
Tags: <craft3><database><ddev>
Title: Craft 3 DDEV Migration: "No database has been selected yet"
ThreadText: # Craft 3 DDEV Migration: "No database has been selected yet"
  
  (Asked by: username_0 on 2023-10-16)
  
  I've hit a snag while trying to move my Craft 3 project from MAMP to DDEV. First I installed a new DDEV project using the `php` project type and MySQL 8.0 for the database. Then I imported the database to DDEV. Then I updated my `.env` variables with the following values:
  
  ```
  DB_DRIVER="mysql"
  DB_SERVER="db"
  DB_PORT="3306"
  DB_DATABASE="db"
  DB_USER="db"
  DB_PASSWORD="db"
  DB_SCHEMA=public
  DB_TABLE_PREFIX=
  
  ```
  
  After that I launched the project in the browser, navigated to the control panel, and got hit with this error:
  
  > No database has been selected yet.
  
  I was able to successfully connect to the database using a plain PHP test script, but Craft can't for some reason.
  
  Aside from checking and re-checking the `.env` settings I'm not exactly sure how else to troubleshoot this. The fact that Craft seems to think this is an installation issue is probably a clue, though I'm not really sure how.
  
  I ran `php craft setup/db-creds` and here's what I got back:
  
  ```
  Which database driver are you using? (mysql or pgsql) [mysql] 
  Database server name or IP address: [db] 
  Database port: [3306] 
  Database username: [db] 
  Use the password provided by $DB_PASSWORD? (yes|no) [yes]:no
  Database password: 
  Database name: [db] 
  Database table prefix: 
  Testing database credentials ... failed: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
  
  ```
  
  Here's what my `config/db.php` file looks like:
  
  ```
  return [
      'dsn' => getenv('DB_DSN'),
      'user' => getenv('DB_USER'),
      'password' => getenv('DB_PASSWORD'),
      'schema' => getenv('DB_SCHEMA'),
      'tablePrefix' => getenv('DB_TABLE_PREFIX'),
  ];
  
  ```
  
  Here's my `ddev describe` output:
  
  ```
  ┌───────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Project: my-project ~/My/Project/Location/my-project https://my-project.ddev.site  │
  │ Docker platform: docker-desktop                                                                   │
  │ Router: traefik                                                                                   │
  ├──────────┬──────┬──────────────────────────────────────────────────────────┬──────────────────────┤
  │ SERVICE  │ STAT │ URL/PORT                                                 │ INFO                 │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ web      │ OK   │ https://my-project.ddev.site                        │ php PHP8.1           │
  │          │      │ InDocker: web:443,80,8025                                │ nginx-fpm            │
  │          │      │ Host: 127.0.0.1:55134,55133                              │ docroot:'dist'       │
  │          │      │                                                          │ Mutagen enabled (ok) │
  │          │      │                                                          │ NodeJS:18            │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ db       │ OK   │ InDocker: db:3306                                        │ mysql:8.0            │
  │          │      │ Host: 127.0.0.1:55132                                    │ User/Pass: 'db/db'   │
  │          │      │                                                          │ or 'root/root'       │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ Mailpit  │      │ Mailpit: https://my-project.ddev.site:8026          │                      │
  │          │      │ `ddev launch -m`                                         │                      │
  ├──────────┼──────┼──────────────────────────────────────────────────────────┼──────────────────────┤
  │ All URLs │      │ https://my-project.ddev.site,                       │                      │
  │          │      │ https://127.0.0.1:55134,                                 │                      │
  │          │      │ http://my-project.ddev.site, http://127.0.0.1:55133 │                      │
  └──────────┴──────┴──────────────────────────────────────────────────────────┴──────────────────────┘
  
  ```
  
  Here's the full Craft error log:
  
  ```
  yii\base\InvalidConfigException: No database has been selected yet. in /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php:320
  Stack trace:
  #0 /var/www/html/craft/vendor/craftcms/cms/src/controllers/InstallController.php(73): craft\controllers\InstallController->_checkDbConfig()
  #1 [internal function]: craft\controllers\InstallController->actionIndex()
  #2 /var/www/html/craft/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
  #3 /var/www/html/craft/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
  #4 /var/www/html/craft/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('index', Array)
  #5 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(295): yii\base\Module->runAction('install/index', Array)
  #6 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(562): craft\web\Application->runAction('install/index')
  #7 /var/www/html/craft/vendor/craftcms/cms/src/web/Application.php(203): craft\web\Application->_processInstallRequest(Object(craft\web\Request))
  #8 /var/www/html/craft/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
  #9 /var/www/html/dist/index.php(21): yii\base\Application->run()
  #10 {main}
  
  ```
  
  **Tags:** craft3, database, ddev
  
  > **Comments:**
  > **username_1**: What does your `config/db.php` file look like?  
  > **username_0**: Edited the question to include it.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-10-18. Score: 1 | Accepted answer
  
  It looks like you’re specifying a `DB_DSN` in your `config/db.php` file, but your `.env` file isn’t defining that variable.
  
  You either need to specify the full `DB_DSN` string in your `.env` file or update your `config/db.php` file to pull in the individual database connection settings from your `.env` file.
  
  > **Comments:**
  > **username_0**: Yup, that was it. For some reason updating `db.php` to use `DB_SERVER` didn't work but adding `DB_DSN="mysql:host=db;port=3306;dbname=db;"` to `.env` did.  
  
  ---
  
  