1

I have two separate Laravel Homestead projects called "Laravel" and "authapp". I would like each of these projects to have their own database.

I have set up my Homestead.yaml file to create one database for each project. And it does just that. However, when I am in my "authapp" project and run the migrate command, it insists on writing to the database specified for the "Laravel" project (the "homestead" database).

Here is my Homestead.yaml file:

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

And my database.php file for the "Laravel" project.

'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,
    ],

And my database.php file for the "authapp" project.

'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,
    ],

I have run vagrant provision a bunch of times and that doesn't do the trick.

Ravioli87
  • 795
  • 13
  • 34
  • 2
    Check that the database `authapp` exist in MySQL. Also check your `.env` file, in the root of the directory, to make sure that `DB_DATABASE` has not accidentally been set – Greg Answer Oct 18 '16 at 01:25
  • 1
    Thanks. The issue was that DB_DATABASE was set to 'homestead'. For future reference, is this not something vagrant provision should take care of? – Ravioli87 Oct 18 '16 at 13:27
  • Possible duplicate of [How to use multiple database in Laravel](https://stackoverflow.com/questions/31847054/how-to-use-multiple-database-in-laravel) – Abdulla Nilam Feb 02 '18 at 10:41

1 Answers1

2

Check that the database authapp exist in MySQL. Also check your .env file, in the root of the directory, to make sure that DB_DATABASE has not accidentally been set.

Whenever you use env('VARIABLE_NAME', 'default value') the VARIABLE_NAME set in the .env file will always override the string value passed in as the second parameter to the env() function.

Greg Answer
  • 717
  • 5
  • 15