bulgaria_mitko's avatar

sqlite dosent work returns - Database (storage/database.sqlite) does not exist.

Hello there i am trying to use sqlite db because i am working with the laracast series for eloquent. My env file is this:

DB_CONNECTION=sqlite
DB_DATABASE=/var/www/html/demos/laracast lessons/elequent-series/storage/database.sqlite

i tried also with DB_DATABASE=storage/database.sqlite but i still get the same error

my database.php file is:

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

I have created the file database.sqlite and i am using tinker and i am able to retrieve data using tinker. everything is working fine, but when i try to fire up a server i get this error: Illuminate \ Database \ QueryException Database (storage/database.sqlite) does not exist. (SQL: select * from "posts" where "id" >= 160)

what i am doing wrong? Why is it not working? Thanks!

0 likes
24 replies
bulgaria_mitko's avatar

@rin4ik , dosent work :( i also tried to change the database to mysql just to see if it will work, but it dosent work as well. i dont know what is going on.....

rin4ik's avatar

show your env db connections when you change to mysql/ what error did you get?

Snapey's avatar

try using a path that does not have a space, or put quotes around it.

Cronix's avatar

I agree, put quotes around the path since it has a space in it.

rin4ik's avatar

try to remove the DB_DATABASE from your .env file and use the default from config/database.php

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

bulgaria_mitko's avatar

well i tried single quotes like this '/var/www/html/demos/laracast lessons/elequent-series/storage/database.sqlite' i tried double quotes as well like this "/var/www/html/demos/laracast lessons/elequent-series/storage/database.sqlite" i also tried to remove the entry in the env file so i had only DB_CONNECTION=sqlite in my file. i also restart the server everything i am doing any change of the file/files and still i am getting the same error!? i am lost :(

Snapey's avatar

have you actually created the file?

go to storage folder and touch database.sqlite

bulgaria_mitko's avatar

we i did, i wrote that i can use all the data in the file using tinker and also i am able to create the migration and also create the seeds as well. for example when i run php artisan migrate --seed i get Nothing to migrate. Seeding: PostsTableSeeder Seeding: Seeds\App\CommentsTableSeeder and also when i run php artisan tinker and then for example: App\Post::find(1); i am getting this:

     id: "1",
     user_id: "621",
     title: "Aut aliquam natus eveniet incidunt velit ut et.",
     body: "Provident inventore saepe ipsum quia ipsum accusantium aut. Consequatur ratione ipsum quas. Et iure hic doloremque veniam molestias.",
     created_at: "2018-03-22 20:24:13",
     updated_at: "2018-03-22 20:24:13",
   }

so i think the problem is not in the file and the db itself. if the tinker commands are working. i am right?

rin4ik's avatar

I had the same problem. and it worked with tinker like in your case I could see users. last thing I can recommend you is go to tinker and type database_path('database.sqlite') copy the path and put it into your .env. it'll be right path.

Snapey's avatar

ok, sorry I did not read that in detail.

So if it works from the command line, the issue is not .env / config related

Check your webserver. How are you starting it? Is it using the right project path? ie, you are tinkering in one project folder but serving another?

bulgaria_mitko's avatar

@rin4ik the path i get from tinker is "/var/www/html/demos/laracast lessons/elequent-series/database/database.sqlite" which i put it in the env file, restart the server and again it does not work :(

@Snapey i am running php artisan tinker from the same folder i am running php artisan server which is who i start my server which in my case the folder name is elequent-series i am lost. i cant figure out what i am doing wrong.... it seems that it should be something very small thing, but i cant cant figure it out what it should be.... :(

bulgaria_mitko's avatar

i moved the project to a new folder and updated the path to the sqlite file in the env file and now i am getting other error: ErrorException (E_WARNING) file_put_contents(/var/www/html/demos/laracast lessons/elequent-series/storage/framework/sessions/YeOXvCMBsE5RuAEj613N5R6ey7qm6FxIECVP4UhH): failed to open stream: No such file or directory

rin4ik's avatar

@bulgaria_mitko maybe it's permission problem with your storage directory. try these lines

sudo rm -R storage/framework/cache/*
sudo rm -R storage/framework/views/*
php artisan cache:clear
chmod 777 -R storage 
composer dump-autoload -o

rin4ik's avatar
rin4ik
Best Answer
Level 50

"/var/www/html/demos/laracast lessons/elequent-series/database/database.sqlite" you see what you got from tinker? it's the path where laravel is looking for your sqlite file . but you put it into storage folder

create database.sqlite file in database folder

to do that in root folder run command

touch database/database.sqlite

return back to your old project and fix that. it'll work and leave please default config from database.php. 'database' => env('DB_DATABASE', database_path('database.sqlite'))

bulgaria_mitko's avatar

still dosent work... i deleted the sqlite file from the storage folder and now thinker is not working and giving me this error

Illuminate\Database\QueryException with message 'Database (storage/database.sqlite) does not exist. (SQL: select * from "posts" where "posts"."id" = 1 limit 1)'

why tinker want to take the sqlite file from storage folder and in the same time when i run database_path('database.sqlite') from inside tinker i get "/var/www/html/demos/laracastSerials/elequent-series/database/database.sqlite" this path. makes no sense,logic,nothing!?

Now both tinker and server/website are not working, because one of them want the file to be in storage and the other want it to be in database. And now i have only one file which is in database and in my env file i have tried to run it with or without DB_DATABASE filed, both times failed...

i am newbie, this makes no sense to me and also one more thing. why the log file of is still saying it to the old folder location inside /var/www/html/demos/laracast lessons/elequent-series/storage/laravel.log i dont get that as well

rin4ik's avatar
composer dump-autoload

I will clone your repo

rin4ik's avatar

try this. and you can store on storage folder your file

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

don't include DB_DATABASE in .env file or include with this path /var/www/html/demos/laracast/lessons/elequent-series/storage/database.sqlite

1 like
bulgaria_mitko's avatar

well i am getting the db error for a sec and then i am getting this error ErrorException (E_WARNING) file_put_contents(/var/www/html/demos/laracast lessons/elequent-series/storage/framework/sessions/MS2lrdLunAeh7nsJa0QqciPSPXX8VnUa873xpgCZ): failed to open stream: No such file or directory full stack

8
ErrorException 
…/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php122
7
 file_put_contents
…/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php122
6
Illuminate\Filesystem\Filesystem put
…/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php83
5
Illuminate\Session\FileSessionHandler write
…/vendor/laravel/framework/src/Illuminate/Session/Store.php129
4
Illuminate\Session\Store save
…/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php87
3
Illuminate\Session\Middleware\StartSession terminate
…/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php218
2
Illuminate\Foundation\Http\Kernel terminateMiddleware
…/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php189
1
Illuminate\Foundation\Http\Kernel terminate
…/public/index.php60
0
 require_once
…/server.php21

more info

Environment & details:

GET Data empty
POST Data empty
Files empty
Cookies
PHPSESSID   
"obsqmirtrafb58llgphhicsndu"
gsScrollPos-214 
"0"
ASP_NET_SessionId   
"6D4E99A114B800B42C609F89"
_okdetect   
"{"token":"15101813587980","proto":"http:","host":"127.0.0.1:4040"}"
_okbk   
"cd4=true,vi5=0,vi4=1510181359079,vi3=active,vi2=false,vi1=false,cd8=chat,cd6=0,cd5=away,cd3=false,cd2=0,cd1=0,"
_ok 
"1700-237-10-3483"
_oklv   
"1510181649763,WLMiUeoGUKWoN1Cc3m39N0N80JEa5BAr"
olfsk   
"olfsk7860510390088493"
wcsid   
"WLMiUeoGUKWoN1Cc3m39N0N80JEa5BAr"
hblid   
"aeuSjuOsBJi3iJ4m3m39N0N80JEA4aAo"
gsScrollPos-541 
""
gsScrollPos-76  
"0"
gsScrollPos-1099    
""
XSRF-TOKEN  
"eyJpdiI6ImdTMDlvZU16VDNcL0VQcXJSNUNBSm1RPT0iLCJ2YWx1ZSI6Imw3TkZrOEdkZldIMGRGaTgzd1JReitUdExDTUNcL2lpUTBKYVdadWw2VXY0REM1bjhIT2F3bVVrb2V1RmNZRnVwUzhibThEb3RQV3N2 ▶"
laravel_session 
"eyJpdiI6IkRldENnTFlkaVRXNlZnNElQZ3N1VkE9PSIsInZhbHVlIjoibGJsMlRSZEdjMTJDcG9BalZSNmZMUDladWhaSHhhaUNxRzRIQTF5eE1Ma1dad25ZeHBrZkloZCtlXC9tUFZqQzNZWE1GbkxxTkRlQnU0 ▶"
Session empty
Server/Request Data
DOCUMENT_ROOT   
"/var/www/html/demos/laracastSerials/elequent-series/public"
REMOTE_ADDR 
"127.0.0.1"
REMOTE_PORT 
"44602"
SERVER_SOFTWARE 
"PHP 7.1.15-0ubuntu0.17.10.1 Development Server"
SERVER_PROTOCOL 
"HTTP/1.1"
SERVER_NAME 
"127.0.0.1"
SERVER_PORT 
"8001"
REQUEST_URI 
"/"
REQUEST_METHOD  
"GET"
SCRIPT_NAME 
"/index.php"
SCRIPT_FILENAME 
"/var/www/html/demos/laracastSerials/elequent-series/public/index.php"
PHP_SELF    
"/index.php"
HTTP_HOST   
"127.0.0.1:8001"
HTTP_CONNECTION 
"keep-alive"
HTTP_USER_AGENT 
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
HTTP_UPGRADE_INSECURE_REQUESTS  
"1"
HTTP_ACCEPT 
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
HTTP_DNT    
"1"
HTTP_ACCEPT_ENCODING    
"gzip, deflate, br"
HTTP_ACCEPT_LANGUAGE    
"bg,en-GB;q=0.8,en;q=0.6,de;q=0.4"
HTTP_COOKIE 
"PHPSESSID=obsqmirtrafb58llgphhicsndu; gsScrollPos-214=0; ASP.NET_SessionId=6D4E99A114B800B42C609F89; _okdetect=%7B%22token%22%3A%2215101813587980%22%2C%22proto% ▶"
REQUEST_TIME_FLOAT  
1521796254.6447
REQUEST_TIME    
1521796254
Environment Variables empty
Registered Handlers
0. Whoops\Handler\PrettyPageHandler

also this

/var/www/html/demos/laracastSerials/elequent-series/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php
     *
     * @param  string  $path
     * @return string
     */
    public function hash($path)
    {
        return md5_file($path);
    }
 
    /**
     * Write the contents of a file.
     *
     * @param  string  $path
     * @param  string  $contents
     * @param  bool  $lock
     * @return int
     */
    public function put($path, $contents, $lock = false)
    {
        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);
    }
 
    /**
     * Prepend to a file.
     *
     * @param  string  $path
     * @param  string  $data
     * @return int
     */
    public function prepend($path, $data)
    {
        if ($this->exists($path)) {
            return $this->put($path, $data.$this->get($path));
        }
 
        return $this->put($path, $data);
    }
 
    /**
     * Append to a file.
Arguments
"file_put_contents(/var/www/html/demos/laracast lessons/elequent-series/storage/framework/sessions/MS2lrdLunAeh7nsJa0QqciPSPXX8VnUa873xpgCZ): failed to open stre ▶"
rin4ik's avatar

does php artisan migrate work now?

bulgaria_mitko's avatar

yes :) php artisan migrate --seed outputs

Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Migrating: 2018_03_21_150440_create_posts_table
Migrated:  2018_03_21_150440_create_posts_table
Migrating: 2018_03_22_194636_create_comments_table
Migrated:  2018_03_22_194636_create_comments_table
Seeding: PostsTableSeeder
Seeding: Seeds\App\CommentsTableSeeder

tinker is also working fine

bulgaria_mitko's avatar

everything is working fine now. everything is working i just had to run php artisan config:cache because it was not updating the files for some reason, i guess laravel are storing those files in the cache and i was updating them, but the files were not updating!

1 like

Please or to participate in this conversation.