Search code examples
laravelherokularavel-10laravel-11

Laravel 11 Heroku: Database file at path [/app/database/database.sqlite] does not exist


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.


Solution

  • 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 )