Lano Angel
Lano Angel

Reputation: 309

Setting custom path for sqlite db in Laravel

I want to use the sqlite db stored in "C:\Folder\my_database.sqlite" , what should i do? I want to use that sqlite db. Can anyone please suggest me a solution?

So i can give the path to sqlite in database.php below:

 'sqlite' => [
            'driver' => 'sqlite',
            'database' => "path to my sqlite db",
            'prefix' => '',
        ],

Also if that is done, then i can change my default connection to sqlite. Like:

DB::setDefaultConnection('sqlite');

Can anyone please suggest me a solution?

Upvotes: 1

Views: 1580

Answers (3)

Jignesh Joisar
Jignesh Joisar

Reputation: 15115

for set sqlite database you can add absoulate path like this in database.php file..

'sqlite' => [
        'driver' => 'sqlite',
        'database' =>  'C:\Folder\my_database.sqlite',
        'prefix' => '',
],

for set a default sqlite connection update this in your .env file:

DB_CONNECTION=sqlite

for production update line(number 16) in database.php

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

and then run this command in terminal for remove old configration and create new configration file.

php artisan config:cache

Upvotes: 1

Md.Sukel Ali
Md.Sukel Ali

Reputation: 3065

Open your .env file and set,

DB_CONNECTION=sqlite
DB_DATABASE=C:\Folder\my_database.sqlite

further more information you can see: https://laravel.com/docs/5.7/database

Upvotes: 2

taavs
taavs

Reputation: 709

As the Laravel Documentation states:

After creating a new SQLite database using a command such as touch database/database.sqlite, you can easily configure your environment variables to point to this newly created database by using the database's absolute path:

 'sqlite' => [
            'driver' => 'sqlite',
            'database' => "C:\Folder\my_database.sqlite",
            'prefix' => '',
        ],

To make it the default connection, just set this in your .env file:

DB_CONNECTION=sqlite

Upvotes: 4

Related Questions