php artisan迁移错误:提供的节点名或服务名或未知 [英] php artisan migrate error: nodename nor servname provided or not know

查看:125
本文介绍了php artisan迁移错误:提供的节点名或服务名或未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的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

,所有服务启动.我的环境文件是:

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

但是当我尝试将迁移与

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 的表:

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/vagrantbox/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文档提到您需要运行 phpartisan migration 命令从您的虚拟机内部进行.

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< containerId> ssh进入容器./bin/bash .然后只需 cd 进入您的项目目录,然后运行 php artisan migration .

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迁移错误:提供的节点名或服务名或未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆