问题
I started learning Laravel just an hour ago and following tutorials.
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' => '',
),
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();
});
}
and migration commands were:
vagrant@homestead:~/Code/Laravel$ php artisan migrate
Migration table created successfully.
Migrated: 2014_08_14_195103_create_users_table
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?
Edit after first comment File: bootstrap/start.php
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
回答1:
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.
回答2:
If anyone finds this looking for the answer for Laravel 5 or later: It's the same as @camroncade says, but in this case it's your .env
file in the project root you want to look at.
回答3:
I am currently dealing with this issue as well. Changed the .env file numerous times as well as the config.php file. Nothing seemed to work. After having done some deep digging into the framework I have found an acceptable temporary workaround to the problem that does not conflict with ANY of Laravel 5.0.2's Exceptions.
NOTE: I'm currently using Ampps 3.4 with php 7.0.2 phpmyadmin 4.4.15.1 on a Windows 8.1 OS.
Inside of the file "ConnectionFactory.php" (located at "laravel\vendor\laravel\framework\src\Illuminate\Database\Connectors"),
scroll down to the public function make
located at line 41.
Within this function you can do the following after this statement $config = $this->parseConfig($config, $name);
which should be on line 43:
$config['database'] = 'Insert the name of your database here';
This change will allow Laravel to continue with its normal process having no negative effect anywhere with the framework or your project. That is until this bug is fixed by the makers of Laravel or the community.
Till then happy coding! =)
来源:https://stackoverflow.com/questions/25317370/changing-database-name-in-laravel-homestead