Data disappearing from sqlite db after a few minutes

I have deployed a Laravel App with a sqlite DB. I am seeing some unexpected behaviour:

When I enter some data, there should be a message popping up after a successful storage in the database. I don’t see this message. Nevertheless, when I go to the app view which shows the stored data, the data is there, so I assume it was successfully stored somehow.

Now, what’s even stranger, is that, after a few minutes, this recently saved data disappears. How can that be possible? How do I fix that?

Ok, after some investigation, it seems that data disappears when the machine stops.

Is there a way to prevent this? Am I missing something?

Hello @jmalonda,

A mounted volume is required to persist SQLite data. Mounting a volume on the storage folder will ensure everything it contains gets persisted, including data on the SQLite database located inside.

Read more here - Laravel and Databases · Fly Docs

Thank you for your response, @motdde .

I imagined that, but thank you for reassuring me.

I created a volume following the doc you mention, so I assume my fly.toml is somehow wrong.



I’d say the database I am accessing is not living in the mounted volume, right? How could I debug this topic?

(This is my first deploy and am kind of struggling)

Thank you!

You can update your [env] for DB_DATABASE to volume mount destination like this DB_DATABASE=“/var/www/html/storage/database/database.sqlite”

You’ll need to update your start-up script

# .fly/scripts/

# Add this below the storage folder initialization snippet
if [ ! -d "$FOLDER" ]; then
    echo "$FOLDER is not a directory, initializing database" 
    mkdir /var/www/html/storage/database
    touch /var/www/html/storage/database/database.sqlite

DB_DATABASE looked like that in the first place, but I got connection errors, so I removed ‘storage’ from the path and it then worked, but now I am facing the current problem.

I’ll give it a spin though and report back, thanks.

Ok, I think I understand.

I updated DB_DATABASE like you said and added your snippet, which I understand creates the database. Naturally, even to my small understanding of Laravel, the database is empty. So I have to run the migrations again. I am having trouble with one migration, but that is another problem. It seems that Laravel connects to the db, so I’ll work now on fixing the faulty migration.

Thanks a lot!!

You are welcome @jmalonda .



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.