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

lara332987's avatar

PHP Artisan Migrate Error

Illuminate\Database\QueryException

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for database failed: Name or service not known (Connection: mysql, SQL: select table_name as name, (data_length + index_length) as size, table_comment as comment, engine as engine, table_collation as collation from information_schema.tables where table_schema = 'laravel' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:829 825▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 826▕ ); 827▕ } 828▕ ➜ 829▕ throw new QueryException( 830▕ $this->getName(), $query, $this->prepareBindings($bindings), $e 831▕ ); 832▕ } 833▕ }

  +39 vendor frames 

40 artisan:37 Illuminate\Foundation\Console\Kernel::handle()

0 likes
2 replies
LaryAI's avatar
Level 58

The error you're encountering indicates that Laravel is unable to connect to the database because it cannot resolve the database host name. This is often a configuration issue in your .env file or your database configuration settings in config/database.php. Here's how you can troubleshoot and resolve this issue:

  1. Check your .env file: Ensure that your .env file has the correct database connection settings. The relevant settings are DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD. For a MySQL database, it might look something like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Make sure that the DB_HOST is set to the correct hostname or IP address of your database server. If you're running the database locally, it's usually 127.0.0.1 or localhost.

  1. Clear Configuration Cache: After making changes to your .env file, you should clear the configuration cache to ensure that Laravel is using the latest configuration. You can do this by running the following Artisan command:
php artisan config:clear
  1. Check Database Server: Ensure that your database server is running and that you can connect to it using the credentials provided in your .env file. You can test the connection using a database client or the command line.

  2. Permissions and Firewall: If the database server is on a remote host, ensure that your server has the necessary permissions to access the remote database server and that no firewall is blocking the connection.

  3. DNS Resolution: If you're using a hostname for DB_HOST, make sure that the hostname can be resolved to an IP address. You can test this by using ping or nslookup commands with the hostname.

  4. Database Exists: Verify that the database specified in DB_DATABASE exists on your database server and that the user specified in DB_USERNAME has the necessary permissions to access it.

If you've gone through these steps and are still facing issues, you may want to provide more context or error messages for further assistance.

lara332987's avatar

My mistake was running the migration using the standard php artisan migrate. Because I am using Lando Dev for local development I need to use lando artisan migrate.

Learning is fun.

Please or to participate in this conversation.