deej
deej

Reputation: 2564

How to make artisan migrate command use database.php instead of .env

By default Laravel's artisan migrate command uses .env file to load database config from but how to make it look at database.php instead of .env file to load database connection information?

If I remove db credentials from .env file it gives me following error:

[InvalidArgumentException] Database [mysql] not configured.

Though database.php has correct connection details.

Upvotes: 1

Views: 2569

Answers (2)

Achraf Khouadja
Achraf Khouadja

Reputation: 6279

Remove this from your .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=new
DB_USERNAME=root
DB_PASSWORD=''

Go to database.php in your config folder

and edit this From

'default' => env('DB_CONNECTION', 'mysql'),

TO

'default' => 'mysql',

if you are using another database (sqlite or sqlserv for exemple, change the default)

AND Dont forget to change the credentials

mysql exemple :

'mysql' => [
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'database',
            'username'  => 'username',
            'password'  => 'password',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
            'engine'    => null,
        ],

in short : you need to remove the database related variables from your .env file and change the env('DB_HOST', 'localhost') or anything similar in your database.php to a simple text between ''

Upvotes: 3

scrubmx
scrubmx

Reputation: 2556

You can use --database to specify the database connection to use:

php artisan migrate --database=pgsql
php artisan migrate --database=mysql
php artisan migrate --database=sqlite

Upvotes: 3

Related Questions