在Laravel/Homestead中更改数据库名称 [英] Changing database name in Laravel/Homestead
问题描述
一个小时前,我开始学习Laravel,并按照教程进行学习.
I started learning Laravel just an hour ago and following tutorials.
我对数据库的设置如下(文件:app/config/database.php):
My settings for database are as follow (File: app/config/database.php):
'default' => 'mysql',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'laraveltest',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
在宅基地的mySQL中,我已经创建了laraveltest
数据库.我还使用以下代码在database/migration
目录中创建了迁移文件:
In mySQL on homestead, I already created laraveltest
database. I also created migration file in database/migration
directory with following code:
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
和迁移命令为:
vagrant@homestead:~/Code/Laravel$ php artisan migrate
Migration table created successfully.
Migrated: 2014_08_14_195103_create_users_table
如图所示,表用户创建但在homestead
数据库中,而不是在laraveltest
数据库中.有人可以告诉我哪里出了问题以及如何强制laravel使用laraveltest
数据库吗?
As displayed, table users created but in homestead
database, not in laraveltest
database. Can someone please tell where I went wrong and how to force laravel to use laraveltest
database?
在第一个评论后编辑 文件:bootstrap/start.php
Edit after first comment File: bootstrap/start.php
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
推荐答案
最有可能是环境问题.检查app/config/local/中是否有数据库配置文件,并检查其设置是否正确.
It is most likely an issue with environments. Check that you have a database configuration file in app/config/local/, and check that it has the proper settings.
这篇关于在Laravel/Homestead中更改数据库名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!