Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alexCharm's avatar

php artisan migrate command gives an error and not creating db tables as expected

I'm a newbie running laravel 8 on Docker and try to create tables on db, it gives following error. This application running as expected before but had to destroy images to switch to another project. now I cannot create default tables using php artisan migrate command. Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = example_app and table_name = migrations and table_type = 'BASE TABLE')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712

0 likes
7 replies
Tray2's avatar

Check your ,env and make sure you have the correct information there.

It should look something like this.

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=<your databases' name>
DB_USERNAME=<user name>
DB_PASSWORD=<password>

If that still doesn't work, try logging in from the terminal

mysql -u<your username> -p

alexCharm's avatar

@Tray2 Thanks for your reply. my DB connection details are fine. I can see the databases when i tried to mysql container terminal.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Show your env (db section) as tray said and your docker-compose.yml. It's important that the host is the internal name of the mysql container, not 127.0.0.1 or localhost

How did you run the migrate command? Inside the container?

2 likes
alexCharm's avatar

@Sinnbeck Thank you for your reply. I did replace DB_HOST in .env file to mysql container name then migration command works as expected.

Please or to participate in this conversation.