推送到Heroku而不覆盖数据库 [英] Pushing to Heroku without overwriting the database

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

问题描述

我有一个更简单的问题,但是由于我是Heroku和整个git概念的新手,所以我有点困惑.老实说,我用谷歌搜索了这个问题,但没有找到足够的答案.也许你可以帮忙.

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.

基于 Flaskr示例,我将其推送到了Heroku,因此我使用了 Heroku Python指南,然后在我的终端机(在Mac上)中使用以下几行来推送更改:

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.

推荐答案

之所以如此,是因为SQLite对于Heroku来说是一个的选择.以下摘录自 Heroku的文档:

That's happening because SQLite is a bad choice for Heroku. The following has been extracted from Heroku's docs:

SQLite在内存中运行,并将其数据存储备份到磁盘上的文件中.尽管此策略可以很好地进行开发,但Heroku的Cedar堆栈具有临时文件系统.您可以写入它,也可以读取它,但是其内容将定期清除.如果要在Heroku上使用SQLite,则将每24小时至少丢失一次整个数据库.

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.

即使Heroku的磁盘持久运行SQLite也不适合.由于SQLite不能作为服务运行,因此每个dyno都将运行一个单独的运行副本.这些副本中的每一个都需要它们自己的磁盘支持的存储.这意味着由于磁盘未同步,为您的应用程序提供动力的每个dyno都将具有不同的数据集.

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.

您可以将应用配置为在Postgres上运行,而不是在Heroku上使用SQLite.

Instead of using SQLite on Heroku you can configure your app to run on Postgres.

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

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