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

rodemarck's avatar

Database (database/database.sqlite) does not exist. (SQL: PRAGMA foreign_keys = ON;)

when a i use migration or use eloquent orm in command route works, but when i use on web route doesn't

0 likes
9 replies
Tray2's avatar

Show us the code generation the error.

rodemarck's avatar

it doesn't work

Route::get('/', function () {
    dd(Cliente::all());
});

but it works

Artisan::command('test',function (){
    $this->comment(Cliente::all());
});
Tray2's avatar

Do you have a database.sqlite in the database directory? Does the webserver have read and write access to it?

Just a guess here but when you run it manually (from the command line) you do that as your user but when you access the route with the browser the webserver is trying to access it and it most likely does not have the correct permissions.

Are you using a *nix (linux/unix/MacOs) machine or are you running Wind0ze?

rodemarck's avatar

Yes, i have it. both are the same project, using a local webserver on windows 10 with "php artisan serve". so i hadn't touch on permission configs, how to see it

Tray2's avatar

I'm not using Windows so I can't help you there.

Tray2's avatar
Tray2
Best Answer
Level 73

I started a new project today and decided to use Sqlite instead of MySql and ran into the same issue.

You need to add the full path to your databae.sqlite.

In my case it's /home/tray2/code/<project-name>/database/database,sqlite

So in your case is something like C:\Users\<your-user>\<project-name>\database\database.sqlite

https://stackoverflow.com/questions/43140711/database-database-database-sqlite-does-not-exist-database-works-from-artisan

1 like
rodemarck's avatar

it's worked, but how to use DIR on env files, to up to cloud in the future?

Tray2's avatar

The easiest would be to ssh into your DO-box and go to your document root and type pwd.

It will print your current working directory.

Just add the output and the pwd command + /database/database.sqlite to your env file and you should be good to go. The path migth look something like this

/var/www/html/public/database/database.sqlite

just a sidenote.

I would most likely not use sqlite in production but rather use a MySQL/MariaDB database. It of course depends on how much data you are going to store in the database.

Please or to participate in this conversation.