Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Django SQLite db from being overwritten while pushing to Heroku

I've got a Django application that is storing a large amount of data in it's models. The problem is, whenever I deploy to Heroku even if it's a small change, the remote database with the correct data gets overwritten with the local database of dummy data.

Scenario:

I have a db file my_db which is remote. Now, when pushing to heroku, I just git add > git commit only the files with the changes rather than the whole project. My problem lies in the fact that, it somehow still overwrites remote database with local data.

Is there a way to prevent this?

like image 896
Newtt Avatar asked May 19 '14 13:05

Newtt


People also ask

Why can we not use SQLite when uploading to Heroku?

Disk backed storage 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.

Can we deploy sqlite3 on Heroku?

However, it seems to be that Heroku doesn't support applications with sqlite3 as the database.


1 Answers

Heroku does not provide a persistent filesystem.

Most Heroku applications that I have worked on use PostgreSQL for their database, so this isn't a problem. But SQLite is just a file sitting in a directory somewhere, so every time you deploy your database will be lost.

The easiest solution is probably to migrate from SQLite to PostgreSQL, which is very well supported on Heroku (and in Django) and will not lose data every time you deploy.

If you're firmly committed to SQLite you may have some other options:

  • Back your database file up before each push and restore it after your push.
  • Add your production database to your Git repository, so it will be deployed along with your application (note that I don't recommend this).
  • Many users use Amazon S3 to store other types of assets. You may be able to use a similar procedure with your database, though I suspect there will be some very significant security risks doing so.
like image 64
Chris Avatar answered Sep 21 '22 01:09

Chris