Laravel 5 Homestead多个数据库

时间:2016-10-17 21:12:25

标签: laravel-5 homestead

我有两个单独的Laravel Homestead项目叫做#34; Laravel"和" authapp"。我希望每个项目都有自己的数据库。

我已经设置了Homestead.yaml文件,为每个项目创建一个数据库。它就是这样。但是,当我在我的" authapp"项目并运行migrate命令,它坚持写入为" Laravel"指定的数据库。项目("宅基地"数据库)。

这是我的Homestead.yaml文件:

provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Code/Laravel
      to: /home/vagrant/Code/Laravel
    - map: ~/Code/authapp
      to: /home/vagrant/Code/authapp

sites:
    - map: homestead.app
      to: /home/vagrant/Code/Laravel/public
    - map: authapp.app
      to: /home/vagrant/Code/authapp/public

databases:
    - homestead
    - authapp

我的" Laravel"的我的database.php文件项目

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'homestead'),
        'username' => env('DB_USERNAME', 'homestead'),
        'password' => env('DB_PASSWORD', 'secret'),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

我的" authapp"的database.php文件项目

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'authapp'),
        'username' => env('DB_USERNAME', 'homestead'),
        'password' => env('DB_PASSWORD', 'secret'),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

我已经多次运行流浪汉条款并且没有做到这一点。

1 个答案:

答案 0 :(得分:2)

检查MySQL中是否存在数据库authapp。另请检查目录根目录中的.env文件,以确保未意外设置DB_DATABASE

每当您使用env('VARIABLE_NAME', 'default value')时,VARIABLE_NAME文件中的.env集将始终覆盖作为env()函数的第二个参数传入的字符串值。