阻止Django SQLite数据库在推送到Heroku时被覆盖 [英] Prevent Django SQLite db from being overwritten while pushing to Heroku

查看:166
本文介绍了阻止Django SQLite数据库在推送到Heroku时被覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django应用程序,它在其模型中存储大量的数据。问题是,每当我部署到Heroku,即使它是一个小的变化,具有正确数据的远程数据库将被本地数据库的虚拟数据覆盖。



场景:



我有一个数据库文件 my_db 哪个是远程的现在,当推送到heroku时,我只是 git添加> git commit 只有具有更改而不是整个的文件项目。我的问题在于,它以某种方式仍然用本地数据覆盖远程数据库。



有没有办法防止这种情况?

解决方案

Heroku 不提供持久性文件系统



我曾经使用过的Heroku应用程序使用PostgreSQL作为数据库,所以这不是一个问题。但是SQLite只是一个位于某个目录的文件,所以每次部署数据库都将丢失。



最简单的解决方案可能是从SQLite迁移到PostgreSQL,这在Heroku(和Django)中得到很好的支持,每次部署时都不会丢失数据。



如果您坚定地致力于SQLite,您可能还会有其他选项:




  • 在每次推送之前,先将数据库文件备份回来,然后将其还原。

  • 将您的生产数据库添加到您的Git存储库,因此它将与您的应用程序一起部署(请注意,我不推荐这个)。

  • 许多用户使用Amazon S3存储其他类型的资产。您可能可以使用类似的过程与您的数据库,虽然我怀疑将有一些非常重要的安全风险这样做。


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?

解决方案

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.

这篇关于阻止Django SQLite数据库在推送到Heroku时被覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆