I’m making some adjustments to a docker project with laravel but I’m having the following problem: SQLSTATE[HY000] [1049] Unknown database ‘ead’. Which is strange because I have the database created, every time I use the command: php artisan migrate I get this error. See my .env file:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=ead
DB_USERNAME=root
DB_PASSWORD=root
I looked for help in some answers here but nothing helped
2
Answers
I will add more information about the project. docker-compose.yml:
.env:
I started using sail, but the problem continues. A new problem has arisen: "SQLSTATE[HY000] [1049] Unknown database 'laravel_ead' (SQL: select * from information_schema.tables where table_schema = laravel_ead and table_name = migrations and table_type = 'BASE TABLE')"
But there is the database when I access phpmyadmin, if I use the command: "docker exec -it laravel-api-ead-mysql-1 mysql -u root -p" and then SHOW DATABASE; my finger banks are:
My banks within phpmyadmin do not appear
It’s hard to give you a definitive answer without seeing your Docker configuration, but one recommendation is to make sure the
DB_HOST
value matches the name of the Docker service that contains your database. For example if yourdocker-compose.yml
looks like this:Then in my
.env
I would useDB_HOST=database
. This is possible because Docker makes the service names of all related containers available as hostnames amongst each other.One way to verify, assuming your Docker structure is similar, is you could start a bash shell against the service container that is running PHP and try to make a database connection directly.
My suggestions are a shot in the dark, but hopefully something here will get you closer to finding your answer.