So I want 2 databases in a single project. I used the code from the answer here So this is my code:
.env
APP_NAME=.....
APP_ENV=local
APP_KEY=......
APP_DEBUG=true
APP_URL=http://Test_Ticket.test
DB_CONNECTION=mysql
DB_HOST=192.168.56.56
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_CONNECTION_SECOND=mysql
DB_HOST_SECOND=192.168.56.56
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=homestead2
DB_USERNAME_SECOND=homestead
DB_PASSWORD_SECOND=secret
database.php:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
],
'mysql2' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST_SECOND', '192.168.56.56'),
'port' => env('DB_PORT_SECOND', '3306'),
'database' => env('DB_DATABASE_SECOND', 'homestead2'),
'username' => env('DB_USERNAME_SECOND', 'homestead'),
'password' => env('DB_PASSWORD_SECOND', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
],
Homestead.yaml:
ip: 192.168.56.56
memory: 2048
cpus: 2
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
-
map: 'C:\Users\lilia\Documents\GitHub\Test tickets'
to: /home/vagrant/code
sites:
-
map: homestead.test
to: /home/vagrant/code/public
databases:
- homestead
- homestead2
features:
-
mysql: true
-
mariadb: false
-
postgresql: false
-
ohmyzsh: false
-
webdriver: false
-
mongodb: false
services:
-
enabled: [mysql]
name: test-tickets
hostname: test-tickets
After I use the command vagrant up, if I understand well, I should have my 2 databases created, but how can I actually connect to both of them if they have the same host and port? I'm using phpstorm and I can only connect to my first "homestead" database. I don't know what to specify to connect to the second one... Those are the parameters I'm using and the response I'm getting:
Also, when I'm trying to run a migration on my second database (homestead2) I'm getting pretty much the same error:
Migration:
Schema::connection('mysql2')->create('files', function (Blueprint $table) {
...
});
And the response I'm getting :
SQLSTATE[HY000] [1049] Unknown database 'homestead2'
So obviously I understand that the second database hasn't been created... So what did I actually did wrong here? Sorry if the question may seem stupid but I'm pretty new to all this...
Edit: changing the database.php or use the command
vagrant up --provision
doesn't change anything