That should work out of the box on Laravel 11, on earlier versions you need to have SQLite3 installed.
You could start with touch database/database.sqlite to create the database file in case it's missing.
I am getting an error when I am trying to call for a model Job using tinker:
Illuminate\Database\QueryException SQLSTATE[HY000]: General error: 10 disk I/O error (Connection: sqlite, SQL: select * from "job_listings").
I wonder what I am missing here? Do I need to change anything in project so SQLite working with tinker or something.
Thanks
That should work out of the box on Laravel 11, on earlier versions you need to have SQLite3 installed.
You could start with touch database/database.sqlite to create the database file in case it's missing.
@Tray2 Thanks for your reply.
I am on laravel 11 and everything is latest. I 've been on other frameworks and rather new to laravel.
Anyways, everything is working good on web, database.sqlite file also exists. It's just tinker not able to access SQLIte may be because it is not set properly in .env so I swtiched to MySQL and it was working both on web and with tinker.
But I am still wondering how SQLite should be defined in .env as there is no username/password and no DB Name exists when we create new project.
@azizabbas It's defined like this
DB_CONNECTION=sqlite
DB_DATABASE=/absolute/path/to/database.sqlite
@Tray2 Thanks for your reply.
Unfortunately, it is still not working with tinker and throwing same error if I try to call on any database method to query anything.
@azizabbas Are you sure that you have access to the database?
in the directory that holds the database file run ls -ltr it should show something like this
-rw-r--r-- 1 tray2 staff 106496 Mar 29 09:06 database.sqlite
@Tray2 Yes, output is similar as you have shown above. I think tinker is unable to connect with SQLite and that is because .env file do not have proper configuration may be. Here is how it looks now in .env
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=/Users/aabbas/Sites/localhost/testing/database/database.sqlite
# DB_USERNAME=root
# DB_PASSWORD=
for diagnostics, in tinker config('database')
try this also php artisan db:show
@Snapey Thanks for your reply on the post. Here are the results of these commands:
mapple.pk@192 testing % php artisan db:show
SQLite ............................................ 3.37.0
Database ....................................... database/database.sqlite
Host ................................................
Port .................................................
Username ......................................
URL ..................................................
Open Connections ......................
Tables ............................................. 10
Total Size ....................................... 80.00 KB
Table ............................................... Size
cache .............................................. 8.00 KB
cache_locks .................................. 8.00 KB
failed_jobs ..................................... 8.00 KB
job_batches .................................. 8.00 KB
job_listings .................................... 4.00 KB
jobs ................................................. 8.00 KB
migrations ..................................... 4.00 KB
password_reset_tokens ............ 8.00 KB
sessions ........................................ 16.00 KB
users .............................................. 8.00 KB
Psy Shell v0.12.3 (PHP 8.2.0 — cli) by Justin Hileman
> config('database');
= [
"default" => "sqlite",
"connections" => [
"sqlite" => [
"driver" => "sqlite",
"url" => null,
"database" => "/Users/aabbas/Sites/localhost/testing/database/database.sqlite",
"prefix" => "",
"foreign_key_constraints" => true,
],
"mysql" => [
"driver" => "mysql",
"url" => null,
"host" => "127.0.0.1",
"port" => "3306",
"database" => "/Users/aabbas/Sites/localhost/testing/database/database.sqlite",
"username" => "root",
"password" => "",
"unix_socket" => "",
"charset" => "utf8mb4",
"collation" => "utf8mb4_unicode_ci",
"prefix" => "",
"prefix_indexes" => true,
"strict" => true,
"engine" => null,
"options" => [],
],
"mariadb" => [
"driver" => "mariadb",
"url" => null,
"host" => "127.0.0.1",
"port" => "3306",
"database" => "/Users/aabbas/Sites/localhost/testing/database/database.sqlite",
"username" => "root",
"password" => "",
"unix_socket" => "",
"charset" => "utf8mb4",
"collation" => "utf8mb4_unicode_ci",
"prefix" => "",
"prefix_indexes" => true,
"strict" => true,
"engine" => null,
"options" => [],
],
"pgsql" => [
"driver" => "pgsql",
"url" => null,
"host" => "127.0.0.1",
"port" => "5432",
"database" => "/Users/aabbas/Sites/localhost/testing/database/database.sqlite",
"username" => "root",
"password" => "",
:
@azizabbas everything looks ok. Artisan is able to read from the sqlite database and dump the table sizes, and this is using the same user account as your user which starts tinker so this would seem to eliminate a permissions error.
According to Artisan, you do have a table job_listings so tinker should be able to read that ok.
I'm out of ideas.
Please or to participate in this conversation.