Pushing to Heroku without overwriting the database
I have a rather more simple question but as I am new to Heroku and the whole git concept I am a bit confused. I honestly googled the problem, but I did not find a sufficient answer. Maybe you can help.
I just started to code a Flask App, based upon the Flaskr example, I pushed it on Heroku, therefore I used the Heroku Python Guide and I push changes using the following lines from my terminal (on Mac):
$ git add -A $ git commit -m "Pushing to Heroku" $ git push -f heroku
Every time I perform a push with this lines my database on production is empty again. But I do not want this to happen all the time. What can I do? Maybe you guys know something about it.
2 Solutions collect form web for “Pushing to Heroku without overwriting the database”
That’s happening because SQLite is a bad choice for Heroku. The following has been extracted from Heroku’s docs:
SQLite runs in memory, and backs up its data store in files on disk. While this strategy works well for development, Heroku’s Cedar stack has an ephemeral filesystem. You can write to it, and you can read from it, but the contents will be cleared periodically. If you were to use SQLite on Heroku, you would lose your entire database at least once every 24 hours.
Even if Heroku’s disks were persistent running SQLite would still not be a good fit. Since SQLite does not run as a service, each dyno would run a separate running copy. Each of these copies need their own disk backed store. This would mean that each dyno powering your app would have a different set of data since the disks are not synchronized.
Instead of using SQLite on Heroku you can configure your app to run on Postgres.
Just modify init_db function to check if entries table already exists: if it does, then don’t load schema.sql