41

I created my database.sqlite file in the database folder. My .env file contents are :

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=absolute\path\to\database\database.sqlite
DB_USERNAME=admin
DB_PASSWORD=

When I run php artisan tinker and DB::table('users')->get(); I get the info from the database.

My DatabaseController is:

class DatabaseController extends Controller
{
    public function main()
    {
        $users = DB::table('users')->get();

        return view('database',compact($users));
    }
}

Yet when I request /database path I get the error:

QueryException in Connection.php line 647: Database (database/database.sqlite) does not exist. (SQL: select * from "users")

UPDATE: A temporary fix is to change the database.php from the config folder:

  'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => 'absolute\path\database\database.sqlite', 
        'prefix' => '',
    ],

Instead of using env('DB_DATABASE', database_path('database.sqlite')), which returns database/database.sqlite not my absolute path.

3
  • how do your run your server? php artisan serve or apache/nginx? Commented Mar 31, 2017 at 12:43
  • 4
    Use the absolute path to the file in your .env Commented Mar 31, 2017 at 12:50
  • 4
    heh, solution for me was to remove the DB_DATABASE entry from my .env altogether. That way it defaulted to using the database_path() function that correctly allowed my app to interact with the database. Commented Aug 4, 2017 at 18:34

16 Answers 16

66

You need to use full path, something like:

DB_DATABASE=/home/laravel-project/database/database.sqlite
Sign up to request clarification or add additional context in comments.

6 Comments

simpler way is to use "../database/database.sqlite"
thats for mac and linux, but windows?
@wafi With Laravel 7.3, writing "../database/database.sqlite" works for the migration, but when trying to login/register, the database is not found. It's found if reverting to database/database.sqlite, but then php artisan migrate doesn't find it anymore, so the solution with full path the good one.
@TuGordoBello for windows use full path replacing single backslash double backslash \\. Eg : DB_DATABASE=C:\\Project_Folder\\database\\database.sqlite
If you are using Ubuntu WSL in Windows the absolute path must include /mnt/c/absolutepath Stop php artisan serve, config:cache, config:clear, serve This is what worked for me.
|
22

If you remove DB_DATABASE=... from your .env file and use the path in the config/database.php:

'database' => env('DB_DATABASE', database_path('database.sqlite')),...

(if your database.sqlite file is in database/ folder), it will work, too.

Comments

12

I ran the following commands:

php artisan config:cache

php artisan config:clear

php artisan serve - restarted the server

Comments

8

In config/database.php file:

'sqlite' => [
              'driver' => 'sqlite',
              'database' => dirname(__DIR__).'/database/database.sqlite',
            ],

Then run following command:

php artisan config:cache
php artisan config:clear

Comments

8

For those who still face this issue: https://laracasts.com/discuss/channels/general-discussion/database-databasedatabasesqlite-does-not-exist-error-on-running?page=1

Since sqlite only require DB_CONNECTION=sqlite in .env file so you just remove the other:

DB_HOST
DB_PORT
DB_DATABASE
DB_USERNAME
DB_PASSWORD

then save and run migration again. This was how I solved the problem. Cheers!

Comments

7

As Chris said in the comments, the main solution is to completely delete DB_DATABASE from the .env file (in fact, only the first line of the following code is needed).

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USERNAME=admin
DB_PASSWORD=

Comments

4

✅ When using sqlite as your db, remove other DB env variables and it should work fine.

I faced the same problem and this solved it perfectly.

DB_DATABASE=sqlite

Remove the others.

Comments

3

For Windows, you need to set up your path like this

DB_DATABASE="C:\\xampp\\htdocs\\project\\data\\database.db"

Comments

3

Just use this one:

DB_DATABASE=../database/database.sqlite

It worked for me.

Comments

2

In your .env file replace DB_DATABASE = database.sqlite to DB_DATABASE = directory_path/project_name/database/database.sqlite

For example: directory_path: C:/xampp/htdocs/project_name/database/database.sqlite

It works fine for me.

Comments

1

I think, that the problem here was because of Homestead. Absolute path to the database.sqlite file on local machine is not the same as the virtual machine one has.

In my case a had to set:

DB_DATABASE=/home/vagrant/code/database/database.sqlite

Or, you can just comment out this line and you are ready to go.

#DB_DATABASE=

Comments

1

Firstly Run this commands:

  php artisan config:cache
  php artisan config:clear
  php artisan serve

Then, You need to use full path, something like:

DB_DATABASE=/home/laravel-project/database/database.sqlite

Configur In config/database.php file:

'sqlite' => [
              'driver' => 'sqlite',
              'database' => dirname(__DIR__).'/database/database.sqlite',
            ],

Make Sure

DB_DATABASE=sqlite

Comments

0

go to the PHP folder from your C: directory and open the file php.ini. From there find extension=pdo_sqlite and remove ;

Comments

0

Faced the same problem. Just had to create the database.sqlite file in the database directory and run my migrations

Comments

0

Hello this has helped me. I hope it could help someone else too.

DB_DATABASE=storage/database.sqlite

this is in the .env file of course before that just create the file with

touch storage/database.sqlite

Comments

0

The solution is easier than it seems. Just install:

sudo apt install php-sqlite3

Okay, now you can run the command:

php artisan migrate

The only configuration required in .env is:

DB_CONNECTION=sqlite

1 Comment

Stack Overflow is an English-only site, but you can use the portuguese version of it: Stack Overflow em Português.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.