Reputation: 141
I'm trying to make a project using Laravel and Sail but I'm getting errors when I'm trying to migrate or do anything related to the project's database (for example, seeding).
More specifically, when using artisan sail migrate
or anything related, I'm getting the following errors:
When DB_HOST=localhost
in my .env
file:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
When DB_HOST=127.0.0.1
in my .env
file:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
What I've tried:
DB_HOST
to localhost and 127.0.0.1 (most common answer online, no succes)sail artisan migrate
./vendor/bin/sail down --rmi all -v
to remove all images and volumesNone of the above have been of succes.
Upvotes: 5
Views: 7479
Reputation: 358
Did you run ./vendor/bin/sail up
after creating and setting .env
?
If not, please execute ./vendor/bin/sail down --rmi all -v
to remove all images and volumes and then just ran ./vendor/bin/sail up
to recreate the images and volumes.
Also as per Laravel docs https://laravel.com/docs/8.x/sail you can connect to db by setting env DB_HOST to mysql
Upvotes: 5
Reputation: 481
T had the same problem with pretty much the same conditions: -I started with a laravel project then moved it to sail
the way I solved this was by adding an entry DB_PORT=3306
in the .env file and changed DB_HOST=localhost
to DB_HOST=mysql
as described in laravel docs : https://laravel.com/docs/8.x/sail#mysql
Upvotes: 1