我已將我的 django 網站部署到 Heroku,但由于網站欄位依賴于我本地機器上的資料庫。我試過使用 Postgres,但 Heroku 上的資料庫沒有在應用程式運行之前填充我需要的資料。有沒有人經歷過這個?我是否需要在 AWS 或其他東西上使用外部資料庫(在這種情況下,最好的方法是什么?)
uj5u.com熱心網友回復:
使用加載資料和轉儲資料:https : //docs.djangoproject.com/en/3.2/ref/django-admin/#loaddata
首先將資料轉儲到本地機器上
python manage.py dumpdata ..other_options > data.json
將它添加到 git 并推送到 herkou
git add data.json
git commit -m "Added data"
git push heroku master
現在 Heroku 可以使用 loaddata 將資料加載到資料庫
heroku run python manage.py loaddata data.json
你完成了。
uj5u.com熱心網友回復:
我已經在 Heroku 上部署了一個 Django 專案,即使在部署后資料仍保留在模型中,我的模型中仍有資料。我在生產中使用 SQLite。Heroku 與 Postgres 一起作業,但在部署時我的資料仍然安全。我剛剛使用 git push heroku main
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/326045.html
