Skip to content
Advertisement

Laravel migrate ends up in wrong database

I have the following settings in .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=unwa
DB_USERNAME=root
DB_PASSWORD=NotForEverybody

When I run

php artisan migrate:fresh

Everything seems to be ok. But when I look at my target database “unwa”, it is empty. A die and dump revealed, that I was connected to another database “auction” that happens to be the first (alphabetically) database. I find all my tables in the “auction” database.

How can I correctly configure my target database “unwa”?

Advertisement

Answer

I had a system environment variable DATABASE_URL that would point to the auction database. This is why it was targeted by the migrations and it could not be found anywhere in the project. Once I removed that environment variable, the migration started to work as expected.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement