Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anon40457's avatar

InvalidArgumentException in SQLiteConnector.php line 34: Database (homestead) does not exist.

I am following the Series Laravel 5 from scratch and I am in specific on the lesson Fetching Data.

I created the database.sqlite file, I added some data from the tinker and was able to retrieve them in the console. Then, I try to replicate what the video does.

My cards controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Http\Requests;

class CardsController extends Controller
{
    public function index()
    {
        $cards = \DB::table('cards')->get();
        return view('cards.index', compact('cards'));
    }
}

However, when I try to load the /cards route I have the following error

nvalidArgumentException in SQLiteConnector.php line 34:
Database (homestead) does not exist.

This is my env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:P3ZgRMRkb2e8+x7S9rDLLB+bKJdR5Unpj8zXBUIHIZE=
APP_URL=http://localhost

DB_CONNECTION=sqlite
DB_FILE=database.sqlite


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
0 likes
12 replies
Gerard's avatar

Check your config/database.php file. Try changing:

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

to this

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

Maybe for some reason Laravel aren't getting your .env variables and it is using the default value. Take a look at this lines too:

'sqlite' => [
            'driver' => 'sqlite',
            'database' => database_path('database.sqlite'),
            'prefix' => '',
        ],
2 likes
anon40457's avatar

I managed to solve it but I am not sure what it had this behaviour. I changed both the default value and the values on the env file, but it didn't work. Then I just removed the related env(...,...) functions and hardcoded to the defaults and it worked.

Raymonf's avatar

Ugh, this is quite annoying. I have the same problem. I tried changing it in env as well, but that didn't work. Eventually I figured out what @dantekavala meant by hardcoding the defaults:

'default' => 'sqlite',
...
'database' => database_path('database.sqlite'),

Perhaps it's a bug?

2 likes
nabil_kadimi's avatar

The value in .env should be the path to the database file relative to the Laravel application directory, in my case it's database/database.sqlite. so for a database file located in [Laravel]/database/database.sqlite, my working configuration was:

DB_FILE=database/database.sqlite

You can understand easily what's going on by reading the code for database_path() and env().

1 like
nwehrhan's avatar

I found a fix to this without hard coding!

You have to change your .env file DB_DATABASE= to the full file path directory of your database. Weird that it works when you do the tinker command in the terminal with just using the sub directory of the database like in the video, but when you artisan serve the webpage the DB_DATABASE= has to be the full directory to return the data.

Below is the fix that will make the terminal tinker calls work and the webpage local host work without changing functions or hardcoding!

http://i.imgur.com/CZk9b0A.png?1

1 like
tpraxl's avatar

My experience on Linux Mint with laravel 5.2 and homestead / vagrant on a virtual box:

You really just need to edit .env Change these values:

DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite

Then inside your bash:

touch database/database.sqlite

Change to your vm. This is important as explained at the bottom of this post.

vagrant ssh

Now the important part: The show-changer was this (supposedly needed after you fiddled around with .env):

cd {project-dir}
php artisan config:clear
php artisan config:cache
php artisan migrate

done.

You should not run config:clear / config:cache on your local machine. You need to run them on your vm!

Running the commands on my local machine led to an improper configuration of the mapped folder. Among a lot of other errors (claiming not to find views etc), I experienced the error:

ErrorException in Filesystem.php line 109: 

file_put_contents({/absolute/path/to/project-on-host-machine}/storage/framework/sessions/e9134ed572d892bf5d2fa85ee4fcc7b7df62d733): failed to open stream: No such file or directory

Which can obviously not be found, because the vagrant machine has another folder mapped (path/to/project-on-guest-machine/ (usually something like ~/code/my-project))

1 like
Rodney's avatar

@nwehrhan 's solution worked for me but i made my .env file - DB_DATABASE='../storage/database.sqlite' for laravel 5.3

RoamingPro's avatar

Laravel Framework version 5.3.18

My .env file's DB section below - ( I removed this line: DB_DATABASE=database.sqlite)

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306

In my database.php file :

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

'sqlite' => [
            'driver' => 'sqlite',
           'database' => database_path('database.sqlite'),
            'prefix' => '',
        ],

You can echo your database path in blade with

 {{ database_path() }}

or the full path and name of the database with

 {{ database_path('database.sqlite') }} 

to see what Laravel is seeing.

More helpers here: https://laravel.com/docs/5.3/helpers

And of course :

php artisan config:clear
php artisan config:cache
skube's avatar

Following along the same video series and I got stuck as well. I simply commented out two lines in my default .env file

#DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
#DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
1 like
Deftly's avatar

I honestly think the site author should update content with notifications about stuff like this for beginners, its disheartening.

Please or to participate in this conversation.