bulgaria_mitko's avatar

Database (database) does not exist. (SQL: select * from "cards")

Hello there its me again :) other yet other problem. i just love laravel :D The course that it should take me 30 min its taking me 3 days :D but never the less right now i manage to migrate succesfully. my database name is database.sqlite and its insite the database folder in my project. After migrating i did php artisan tinker and added two rows into my database.

DB::table('cards')->insert(['title' => 'My Second Card', 'created_at' => new DateTime, 'updated_at' => new DateTime]); => true

DB::table('cards')->insert(['title' => 'My First Card', 'created_at' => new DateTime, 'updated_at' => new DateTime]); => true

and then when i run DB::table('cards')->get(); i get 2 rows from my table as you can see:

DB::table('cards')->get(); => Illuminate\Support\Collection {#663 all: [ {#672 +"id": "1", +"title": "My Second Card", +"created_at": "2017-01-12 13:14:31", +"updated_at": "2017-01-12 13:14:31", }, {#661 +"id": "2", +"title": "My First Card", +"created_at": "2017-01-12 13:15:03", +"updated_at": "2017-01-12 13:15:03", }, ], }

but when i try to open localhost:8000/cards from my browser i got this error:

2/2 QueryException in Connection.php line 770: Database (database) does not exist. (SQL: select * from "cards")

1/2 InvalidArgumentException in SQLiteConnector.php line 34: Database (database) does not exist.

i tried a few things and none of them works i even installed sudo apt-get install sqlitebrowser and open the database and saw the two rows i created with artisan tinker, but why it says it cant find my database and still im able to do php artisan migrate? makes no logic for me. what im missing? thanks

0 likes
4 replies
tomopongrac's avatar
Level 51

Check your config/database.php file

do you have these

'default' => env('DB_CONNECTION', 'sqlite'),

'sqlite' => [
            'driver' => 'sqlite',
            'database' => database_path('database.sqlite'),
            'prefix' => '',
        ],
bulgaria_mitko's avatar

yes:

'default' => env('DB_CONNECTION', 'sqlite'),

'connections' => [

    'sqlite' => [
        'driver' => 'sqlite',
        'database' => env('DB_DATABASE', database_path('database.sqlite')),
        'prefix' => '',
    ],
bulgaria_mitko's avatar

now it worked @tomi , but that dont make any sense with me, why the default code when i installed laravel project:

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

and you code:

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

and it is working with ur code and not working with the default one provided from when i installed laravel project. i didnt check that and i was not thinking there is any problem because of that and one more thing :(( but thank you very much for helping!

Please or to participate in this conversation.