Laravel 5 : Use different database for testing and local

后端 未结 6 1475
栀梦
栀梦 2020-12-24 12:21

How does one change database for development and testing on local system without editing the .env file each time?

I have found it quite inconvenient to

6条回答
  •  鱼传尺愫
    2020-12-24 12:36

    For those, who want to use sqlite for testing

    Create a test environment file and test.sqlite file

    > cp .env .env.testing
    > touch test.sqlite
    

    In .env.testing file

    DB_CONNECTION=sqlite
    DB_DATABASE=./test.sqlite
    

    Followed by

    php artisan config:cache --env=testing
    

    Now again migrate your databases

    php artisan migrate
    

    if you need then seed it

    php artisan db:seed
    

    And whenever you want to use local env, run

    php artisan config:cache --env=local
    

    Please note, env name can be found in .env file as APP_ENV=local

提交回复
热议问题