php artisan migrate错误:提供或不知道节点名或服务名

php artisan migrate error: nodename nor servname provided or not know(php artisan migrate错误:提供或不知道节点名或服务名)
本文介绍了php artisan migrate错误:提供或不知道节点名或服务名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I'm in trouble with my laradock project: i have downloaded and installed docker and i have successfully completed the setup of my laravel project with laradock. I use php 7, laravel(5.5.14) and the latest version of laradock. I start my project writing in shell:

docker-compose up -d nginx mysql

然后所有服务都启动了.我的 env 文件是:

and all services starts. My env file is:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=root

但是当我尝试将迁移与

But when i try to use the migration with

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_tablecreate_password_reset_tablecreate_customer_table(我写了这个文件).我需要在我的数据库中创建一个名为 customer 的表,其中包含一些列:

My db called homestead is created and it works. In my laravel project, under the migration folder i have 3 files php: create_user_table, create_password_reset_table and create_customer_table( i have wrote this file). I need to create a table in my db called customer with some colums:

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();
    });

如何完成迁移并创建表?谢谢解答!

How can i complete the migration and create the table? Thank you for answer!

推荐答案

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

@Stefano Zaniboni answered this in a comment but to expand:

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

I ran across this issue because I'm used to running php artisan commands in my local directory rather than in a virtualbox / vagrant box / docker container.

Laravel Docs 提到您需要运行 phpartisan migrate 命令从你的虚拟机中.

The Laravel Docs mention that you need to run the php artisan migrate command from within your virtual machine.

如果您使用 docker,则可以使用 docker ps 获取容器 ID.然后使用 docker exec -it ssh 进入容器./bin/bash.然后只需 cd 进入您的项目目录并运行 php artisan migrate.

If you're using docker, you can get your container id using docker ps. Then to ssh into the container use docker exec -it <containerId> /bin/bash. Then just cd into your project directory and run php artisan migrate.

这篇关于php artisan migrate错误:提供或不知道节点名或服务名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)