Heroku:每次 dyno 重新启动时都会丢失 Django 数据库文件

2021-12-16 00:00:00 django heroku persistence sqlite

我在 Heroku 上部署了一个 Django 应用程序.我有一些模型并将一些数据插入到数据库(SQLite 数据库)中.但是,当我在一段时间后尝试访问数据时,它显示一个空数据库.我在这里发现了一个类似于我的问题的问题 ->django heroku 媒体文件 404 错误 我明白了,我应该把我的媒体文件放在别的地方.

这里我的问题是数据库,我的问题是,我可以防止我的 SQLite 数据库 发生这种数据丢失吗?

I deployed a Django app on Heroku. I have some models and inserted some data to the database (SQLite database). But, when I tried to access the data after certain time, it showing an empty database. I found a problem similar to my issue here ->django heroku media files 404 error and I understood that, I should keep my Media files somewhwere else.

Here my problem is with database and my question is, can I prevent my SQLite database from this data loss ?

推荐答案

除了将数据库存储在 Amazon S3 等其他服务上之外,您无能为力.Heroku 具有临时存储:https://devcenter.heroku.com/articles/sqlite3#磁盘备份存储

There is nothing you can do about this, short of storing the database on some other service like Amazon S3. Heroku has ephemeral storage: https://devcenter.heroku.com/articles/sqlite3#disk-backed-storage

然而,Heroku 还附带免费的持久 PostgreSQL.所以我建议你改用它.

However, Heroku also comes with free persistent PostgreSQL. So I would advice you to use that instead.

相关文章