Prevent Django SQLite db from being overwritten while pushing to Heroku

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.

Leave a Comment