Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run migrations in Laravel 8: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known [closed]

I don't get why my migrations are failing on a clean install of Laravel 8. This is what am getting:

 Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = bunny and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

I am using Kali linux with a perfect Laravel environment, but version 8 just won't work.

like image 834
moses kamau Avatar asked Dec 10 '20 15:12

moses kamau


People also ask

Why can't laradock login to the database in Laravel?

This does occur when trying to run a migration from inside the workspace - where both the version of php and mysql should be controlled by Laradock. Laravel should be able to login to the database and do its thing.

How does the Order of migrations work in Laravel?

Each migration filename contains a timestamp that allows Laravel to determine the order of the migrations: Laravel will use the name of the migration to attempt to guess the name of the table and whether or not the migration will be creating a new table.

What is up and down method in Laravel migration?

A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method. Within both of these methods, you may use the Laravel schema builder to expressively create and modify tables.


2 Answers

just in .env file change the value of DB_HOST to 127.0.0.1

"change DB_HOST=mysql to DB_HOST=127.0.0.1"

like image 175
hussain Avatar answered Oct 16 '22 16:10

hussain


Changing the value of DB_HOST to 127.0.0.1 within the .env file did not solve my problem completely, I also had to rebuild the whole docker/sail with:

sail down -v

and

sail build --no-cache

and first then after running

sail up -d

I could run:

./artisan migrate:fresh

Rebuilding is required when there was changes to the database credentials.

like image 1
trojan Avatar answered Oct 16 '22 16:10

trojan