是否可以使用 Sqlite 部署 Django?

2021-12-16 00:00:00 python postgresql django heroku sqlite

我已经构建了一个使用 sqlite(默认数据库)的 Django 应用程序,但是我找不到任何允许使用 sqlite 进行部署的地方.Heroku 只适用于 postgresql,我花了两天时间尝试切换数据库但无法弄清楚,所以我只想用 sqlite 进行部署.(这只是一个小应用.)

I've built a Django app that uses sqlite (the default database), but I can't find anywhere that allows deployment with sqlite. Heroku only works with postgresql, and I've spent two days trying to switch databases and can't figure it out, so I want to just deploy with sqlite. (This is just a small application.)

几个问题:

  • 有什么地方可以使用 sqlite 进行部署吗?
  • 如果是,在哪里/如何?

推荐答案

SQLite 是磁盘上的数据库,它对于开发目的非常有用,但是像 Heroku 这样的服务希望您的服务器端代码是无状态的,这作为结果并没有真正允许使用诸如 SQLite 之类的数据库.我想你可以让它工作(前提是你在 Heroku 的磁盘上找到了一个地方来放置你的 SQLite 数据库)但是每次重新部署时你都会不断丢失数据库的内容.

SQLite is a database on the disk, it is very useful for development purposes, however services like Heroku expect your server-side code to be stateless, which as a consequence does not really allow for databases such as SQLite. I guess you could make it work (provided you find a place on Heroku's disk where to put your SQLite db) but you would constantly lose your database's content every time you redeploy.

对于 Heroku,我会将您重定向到 此链接,其中解释了如何在 Heroku 上使用 Django 和 PostgreSQL.

For Heroku specifically, I'll redirect you to this link which explains how to use Django with PostgreSQL on Heroku.

相关文章