0

I have an existing laravel application that technically works fine (local computer). I connect to the DB, do many things with it and everything is fine.

I added a migration and when trying to migrate it, I get the following error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = dbname and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +36 vendor frames 
  37  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
  • Laravel version: 7.30.6
  • PHP version 7.4.21
  • Using MAMP on a Mac if it makes a difference.

my .env:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root

For some reason, I tried changing the DB_HOST to "127.0.0.1" and it would not work.

I tried many things, but nothing works:

  • Cache clearing
  • Config caching and clearing
  • Composer update
  • Composer install
  • Composer dump-autoload

Nothing seems to be working.

Though it makes no sense because everything else is working perfectly, and the migration seems to not be able to connect to the DB. (I checked and there indeed is a migrations table)

Any tips would be much appreciated here.

Thank you

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
Avi
  • 728
  • 3
  • 10
  • 20

1 Answers1

0

Found the answer here.

I've been trying to solve this for hours and it was a simple fix - it's a mac specific issue. Just add:

DB_SOCKET='/Applications/MAMP/tmp/mysql/mysql.sock'

And cache your config and it'll work. At least it did for me.

Avi
  • 728
  • 3
  • 10
  • 20
  • NEVER cache config on a dev environment as it will just generate a LOT of issues, specially when running TESTS. And do yourself a good favor, switch to Docker, you can either use [Laravel Sail](https://laravel.com/docs/10.x/sail) or find your own implementation, it will help you learn a LOT and also not have this stupid errors in the future. Have in mind that most companies use Docker, so it will help you professionally – matiaslauriti May 21 '23 at 18:00
  • Thanks. I never heard that before. Regarding Docker - yes, I'm aware. I tried it in the past and I just couldn't make it work normally for me. I agree though that I need to find some more normal implementation that won't be problematic. Thanks – Avi May 22 '23 at 12:07