Prevent Django overwrite SQLite db when clicking on Heroku

I have a Django application that stores a large amount of data in it. The problem is that whenever I deploy to Heroku, even if this is a small change, the remote database with the correct data gets overwritten by the local dummy data database.

Scenario:

I have a db file my_db which is remote. Now, when I click on the hero, I just git add > git commit only the modified files, not the entire project. My problem is that it somehow overwrites the remote databases with local data.

Is there any way to prevent this?

+6
source share
2 answers

Heroku does not provide a permanent file system .

Most of the Heroku applications I worked on use PostgreSQL for their database, so this is not a problem. But SQLite is just a file somewhere in the directory, so every time you deploy your database, it will be lost.

The simplest solution is probably to switch from SQLite to PostgreSQL, which is very well supported on Heroku (and in Django) and will not lose data with every deployment.

If you are strongly committed to SQLite, you may have other options:

  • Return the database file before each click and restore it after clicking.
  • Add your production database to the Git repository, so it will be deployed with your application (note that I do not recommend this).
  • Many users use Amazon S3 to store other types of assets . You can use a similar procedure with your database, although I suspect that this will lead to very serious security risks.
+3
source

You must add the db file to .gitignore

0
source

Source: https://habr.com/ru/post/969529/


All Articles