DEV Community

Devtonight
Devtonight

Posted on • Updated on • Originally published at devtonight.com

How To Fix Laravel SQLite "Database does not exist" error?

First, check whether that you made necessary environment variable changes in .env file as described in the How To Use SQLite Database In Laravel question. If you have already tried it but not working, comment all the database related lines in the .env file like this.

#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=laravel
#DB_USERNAME=root
#DB_PASSWORD=
Enter fullscreen mode Exit fullscreen mode

This will completely prevent loading the database configuration from the .env file. Then open the database.php file in the config directory to mention the configuration directly.

But before continuing, it should not be encouraged to hard-code environment variables directly into the code. But in this scenario, the SQLite connection does not require any username or password as MySQL does.

So, change the default database connection to SQLite.

'default' => env('DB_CONNECTION', 'sqlite'),
Enter fullscreen mode Exit fullscreen mode

In the connections array, only change the database line as following and leave other lines as they are,

'sqlite' => [
    'database' => database_path('database.sqlite'),
],
Enter fullscreen mode Exit fullscreen mode

After that, try to run the migration:status command.

php artisan migrate:status
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
martinhansell profile image
Martin Hansell • Edited

Hi - thanks for this very useful guide! It's useful because at least I now know I've gotten this far! BUT I still can't get through Page 1 of Laravel's Bootcamp because I'm not getting a database connection.

I've amended this line in database.php to reflect my target database:
'database' => /home/theologenius/Documents/GitRepos/chirper/database/('database.sqlite'),

I've tested it as you suggested. Below is the output from your last-suggested php artisan migrate:status command.

Image description

This seems to state that all's working well. But when I try to login to the localhost:8000/login page I'm still getting an error and can't appear to move forward.

Image description

Wondered if you could help me to troubleshoot that???

Thanks in advance and for your post!
Martin

Collapse
 
drfcozapata profile image
Francisco Zapata

Thanks bro!
Blessings