Skip to content
Advertisement

IlluminateDatabaseQueryException SQLSTATE[HY000] [2002] No such file or directory but migrations works [closed]

first time I ask via the web, but I don’t know what I can do anymore. My question is about laravel using Eloquent. I have no problems with migrations and seeding and have a connection to MySQL. But when I try to build a controller and want to store data on my existing table car. here is an example:

JavaScript

But when i want to start the URL which uses the method the following error arise:

IlluminateDatabaseQueryException SQLSTATE[HY000] [2002] No such file or directory (SQL: insert into cars (updated_at, created_at) values (2022-01-16 13:26:17, 2022-01-16 13:26:17))

I looked into the other solutions but they only discuss the connection to MySQL and because of the migration, I think that my connection is totally fine. I tried everything with my env. and database.php file but found nothing wrong. maybe you can help me. Here my env. file:

JavaScript


and here my database.php file:
JavaScript

Additional here is the model car:
JavaScript

And here my car _migration:

JavaScript

Thank u for your help. I will answer quickly if anything is not clear enough.

Greetings Fermain

Advertisement

Answer

I found the answer to my issue. I used MAMP and Docker at the same time. The problem is that Mama is on the server, and docker is lokal on the computer. So I got two databases. But the password for the database was not set in Docker. So I got access to my server database with the properties in env. And no access to my docker database, which the eloquent wanted to store. So I deleted MAMP from my computer and tried to access MySQL with

docker exec -it MySQL MySQL -uroot -p

but the password was wrong. So I used the command of What’s the default password in docker container MySQL-server when you don’t set one? from nischay, and this generates a new password. I set this password in docker exec -it MySQL MySQL -uroot -p, and I was in the MySQL bash. After this, I reset the password with ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘new_password;

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement