大家好,我真的希望为我的问题找到解决方案。所以我找不到这个问题的解决方案,而且它不断出现 我在laravel + vue.js项目中使用docker,并且尝试运行
docker-compose up -d
一切似乎都正确,但是当我尝试迁移数据库时:
php artisan migrate
出现此错误:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Hte inconnu. (SQL: select * from information_schema.tables where table_schema = pfe and table_name = migrations)
at C:\xampp\htdocs\Laravel\Licence\vendor\laravel\framework\src\Illuminate\Database\Connection.php: 664
660: // If an exception occurs when attempting to run a query, we'll format the error
661: // message to include the bindings with SQL, which will make this exception a
662: // lot more helpful to the developer instead of just the database's errors.
663: catch (Exception $e) {
664: throw new QueryException(
665: $query, $this->prepareBindings($bindings), $e
666: );
667: }
668:
669: return $result;
Exception trace:
1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Hte inconnu. ")
C:\xampp\htdocs\Laravel\Licence\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 70
2 PDO::__construct("mysql:host=app_db;port=3306;dbname=pfe", "root", "", [])
C:\xampp\htdocs\Laravel\Licence\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 70
Please use the argument -v to see more details.
这是我的.env文件
NGINGX_ROOT=/usr/share/nginx/teamworking
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:EcJdGpFhoJWDLnbubsfwMBY1NGzSRXSS83bhTqmOhDc=
APP_DEBUG=true
APP_URL=127.0.0.1
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=app_db
DB_PORT=3306
DB_DATABASE=pfe
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=app_redis
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
JWT_SECRET=vpOw276VnRBlVENmQhnT7FtORham0JwJjVIX2iEKhlrlNgtFt4U1YtD9Xhg3yT5R
答案 0 :(得分:0)
我有同样的问题。 DB_HOST必须类似于localhost或127.0.0.1。
因此,在您的情况下,请通过DB_HOST = localhost替换DB_HOST = app_db,然后重试 php artisan迁移。
您可以在迁移完成后放入app_db。
我希望有帮助
答案 1 :(得分:0)
将 DB_HOST=app_db
更改为 DB_HOST=localhost
并再次迁移。