Laravel Sail rebuild default database

  docker, laravel, laravel-sail, mysql

According to docs:

Also, when the MySQL container is starting, it will ensure a database exists whose name matches the value of your DB_DATABASE environment variable.

My .env file looks like this.

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

Yet when I try to run the migrations via sail artisan migrate, I get back this error:
SQLSTATE[HY000] [1049] Unknown database 'test' (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')

What I’ve tried:

  • Removing the docker container and images all together.
  • Running sail build --no-cache (to try and rebuild everything altogether)
  • When running sail shell, I went into MySQL and showed all databases. I could see the default laravel database there.

How do you tell sail to create the correct DB_DATABASE?

Source: Docker Questions

LEAVE A COMMENT