gpt4 book ai didi

php artisan 迁移错误 : nodename nor servname provided or not know

转载 作者:行者123 更新时间:2023-12-04 11:43:14 28 4
gpt4 key购买 nike

我的 laradock 项目遇到了麻烦:我已经下载并安装了 docker,并且我已经使用 laradock 成功完成了我的 laravel 项目的设置。我使用 php 7、laravel(5.5.14) 和最新版本的 laradock。我开始在 shell 中编写我的项目:

docker-compose up -d nginx mysql

并启动所有服务。我的 env 文件是:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=root

但是当我尝试使用迁移时
php artisan migrate

我收到此错误:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = homestead and table_name = migrations) 
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known

我的名为 homestead 的数据库已创建并且可以正常工作。在我的 Laravel 项目中,在迁移文件夹下我有 3 个文件 php:create_user_table、create_password_reset_table 和 create_customer_table(我写了这个文件)。我需要在我的数据库中创建一个名为 customer 的表,其中包含一些列:
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->boolean('azienda');
$table->string('iva');
$table->string('ds');
$table->boolean('fatres');
$table->string('cf');
$table->string('mail');
$table->string('telefono');
$table->integer('sponsor');
$table->string('indinst');
$table->string('civinst');
$table->string('cityInst');
$table->string('capinst');
$table->string('provinst');
$table->string('indf');
$table->string('civf');
$table->string('capf');
$table->string('provf');
$table->string('cityFatt');
$table->timestamps();
});

如何完成迁移并创建表?谢谢你的答案!

最佳答案

@Stefano Zaniboni 在评论中回答了这个问题,但要扩展:

我遇到这个问题是因为我习惯运行 php artisan命令在我的本地目录中,而不是在 virtualbox/vagrant box/docker 容器中。

Laravel Docs提到您需要运行 php artisan migrate虚拟机中的命令。

如果您使用 docker,则可以使用 docker ps 获取容器 ID。 .然后通过 ssh 进入容器,使用 docker exec -it <containerId> /bin/bash .那么就cd进入你的项目目录并运行 php artisan migrate .

关于php artisan 迁移错误 : nodename nor servname provided or not know,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46725734/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com