2

I have this situation in laravel 5.2 where if I do this:

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=
DB_DATABASE=database/database.sqlite
DB_USERNAME=
DB_PASSWORD=

in the .env file I get this:

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

on trying to manipulate the laravel error rendering system with this code from a controller:

<?php

namespace App\Http\Controllers;

use App\User;

class SampleController extends Controller
{
    public function findUser()
    {
       $user = User::firstOrFail();

       return $user->toArray();
    }
}

And this goes well with php artisan migrate command, but to get the controller code to render the error as expected I have to do this:

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=
DB_DATABASE=../database/database.sqlite
DB_USERNAME=
DB_PASSWORD=

To fix the problem so I get both php artisan migrate and SampleController to work I have put this in the config/database.php file:

'connections' => [

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

Why is the default means to access sqlite as given on the laravel website not working. Is it a bug I should be aware of?

1
  • The config.php file is normally expected to contain 'database' => env('DB_DATABASE', database_path('database.sqlite')), in it's 'sqlite' array. Commented Aug 6, 2016 at 12:25

1 Answer 1

2

The normal configuration in the config.php file is expected to be

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

Furthermore, the appropriate way to mention the DB_DATABASE in the .env file is to specify the absolute file name, such as /var/www/laravel/database/database.sqlite not the relative location.

For example, in Windows

DB_DATABASE=C:\wamp\www\laravel\database\database.sqlite

And this is what is mentioned in the Laravel Documentation

DB_DATABASE=/absolute/path/to/database.sqlite
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.