skip to Main Content

I have upgraded my laravel application from 10-11 using Shift. Everything seems fine locally, when I deploy it to Heroku I get this error, I am not using any database in my application:

Database file at path [/app/database/database.sqlite] does not exist. Ensure this is an absolute path to the database. (Connection: sqlite, SQL: select * from "sessions" where "id" = I6dWWr8bFKzuCRdSvXnG7vW1H5keVr09MUW3gRht limit 1)

public/index.php :17

// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';
 
// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../bootstrap/app.php')
    ->handleRequest(Request::capture());

This is my config/database:

<?php

return [

    'migrations' => [
        'table' => 'migrations',
        'update_date_on_publish' => false, // disable to preserve original behavior for existing applications
    ],

];

I tried to create that file in storage and deployed again, didn’t work.

2

Answers


  1. Chosen as BEST ANSWER

    Just like Arun A S said, the Laravel Shift update removed config/session.php to minimize the app based on the Laravel 11 structure. Therefore, the session driver defaulted to "database".

    I brought that file back and included:

    'driver' => env('SESSION_DRIVER', 'file')
    

    Alternatively, you can add that to the environment variables using Heroku settings/config vars.


  2. Laravel 11 changed the default session driver from file to database https://github.com/laravel/laravel/blob/4ef5e2f89e987f84b33b62f79e96485dcaa8f209/.env.example#L29

    The SQL error you are receiving is related to this as Laravel is trying to read the session from the database but can’t connect to the database.

    To revert this and use the file driver like in previous versions of Laravel, you can set the session driver to file in your .env file

    SESSION_DRIVER=file
    

    Alternatively you can stick with the database session driver by creating the sqlite database. To do this, you need to create a file named database.sqlite at the path <path-to-application>/app/database/database.sqlite. This file should not be commited to your source control ( git, svn, etc )

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search