tanmay_das's avatar

QueryException in Connection.php line 647: Database (database/database.sqlite) does not exist.

I have been following along the Laravel 5 from scratch tutorial series and I am now stuck at lecture 7 which is about the DB migration. I was able to create table and insert rows into it from the tinker but when I try to query the db from controller I get the above-mentioned error. Here is my .env file:

APP_ENV=local
APP_KEY=base64:nvSV7OF0nXn+KTsVRypOReXNSruqXb0pzBEFB/6vENw=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database/database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

And here is my sqlite config in database.php file:

'default' => env('DB_CONNECTION', 'sqlite'),
'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

One other thing that I have noticed is whatever value I assign to DB_DATABASE, the error is always pointing to database/database.sqlite. For instance even if I change the DB_DATABASE value to abc.sqlite, I will still get an InvalidArgumentException in SQLiteConnector.php line 34: Database (database/database.sqlite) does not exist. [at SQLiteConnector->connect(array('driver' => 'sqlite', 'database' => 'database/database.sqlite', 'prefix' => '', 'name' => 'sqlite')) in ConnectionFactory.php line 221]

0 likes
1 reply
tanmay_das's avatar

Solved the issue by replacing this line 'database' => env('DB_DATABASE', database_path('database.sqlite')), with this: 'database' => database_path('database.sqlite'),

From a beginners point of view, I find this db configuration of laravel way too complicated. There should be an out-of-the-box way to handle this :(

Please or to participate in this conversation.