php 迁移期间数据库未配置 laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31548044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Database not configured laravel during migration
提问by m2j
This might be repeated question. But I had no luck with previous answers
这可能是重复的问题。但我对以前的答案不走运
I just git clone
a laravel project. Now I tried to do php artisan migrate
. It returns the below error.
我只是git clone
一个 Laravel 项目。现在我试着做php artisan migrate
。它返回以下错误。
[InvalidArgumentException]
Database [] not configured.
and
和
migrate [--bench[="..."]] [--database[="..."]] [--force] [--path[="..."]] [--package[="..."]] [--pretend] [--seed]
my app/config/database.php
is like this:
我app/config/database.php
是这样的:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'upgrade',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I do create the upgrade
database in mysql
.
我确实upgrade
在mysql
.
could anyone tell me what I'm doing incorrectly?
谁能告诉我我做错了什么?
thanks in advance.
提前致谢。
回答by siva
I had the same issue. I have cloned the L5.1 project from GIT and i performed
我遇到过同样的问题。我已经从 GIT 克隆了 L5.1 项目并且我执行了
composer install
composer update
and also configured DB details in .env (by default .env is not present so i took the copy of .env.example and renamed as .env). After that if tried to run
并且还在 .env 中配置了数据库详细信息(默认情况下 .env 不存在,所以我获取了 .env.example 的副本并重命名为 .env)。之后,如果尝试运行
php artisan migrate
I got the same exception like as @users4393829 mentioned. I tried follow commands to find and set the database.
我遇到了与@users4393829 提到的相同的异常。我尝试按照命令来查找和设置数据库。
php artisan tinker
>>> Config::get('database.connections.mysql.database');
>>>null
>>>Config::set('database.connections.mysql.database','homesteaed');
>>>Config::get('database.connections.mysql.database');
>>>homesteaed
After doing all this things i found that there is no database.php file so i have placed it in the 'config' folder and ran the migration it works. Please make sure that you have any config files is git ignored in your project.
完成所有这些事情后,我发现没有 database.php 文件,所以我将它放在“config”文件夹中并运行了它的迁移。请确保您有任何配置文件在您的项目中被 git 忽略。
回答by 4givN
回答by rully martanto
Just remove .env file and put new to replace
只需删除 .env 文件并放置新的替换
回答by jwh
I had the same problem, turns out the .env
that shipped with the framework defaulted the DB_HOST
to localhost
and had DB_PORT set.
我遇到了同样的问题,结果.env
是框架附带的默认设置DB_HOST
为localhost
并设置了 DB_PORT。
Changed the host to the FQDN of the machine and it worked fine. I'm guessingif you're connecting to localhost
it expects a socket and not a port.
将主机更改为机器的 FQDN,它工作正常。我猜如果你连接到localhost
它需要一个套接字而不是一个端口。