Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database (database/database.sqlite) does not exist. Database works from artisan tinker

Tags:

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.

like image 544
Alexandru Antochi Avatar asked Mar 31 '17 12:03

Alexandru Antochi


2 Answers

You need to use full path, something like:

DB_DATABASE=/home/laravel-project/database/database.sqlite 
like image 52
Alexey Mezenin Avatar answered Oct 05 '22 22:10

Alexey Mezenin


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.

like image 33
gdfgdfg Avatar answered Oct 05 '22 22:10

gdfgdfg