简体   繁体   English

部署到Heroku后如何与postgresql数据库连接?

[英]How to connect with postgresql database after deployment to Heroku?

I'm new to Django but I'm deploying a Django-based website to Heroku, using Postgresql. 我是Django的新手,但是我正在使用Postgresql将基于Django的网站部署到Heroku。 The deployment was successful, and the website is online and has established connection with the database. 部署成功,并且网站在线并且已与数据库建立连接。 However, none of the data from my local database has migrated to the heroku database, causing it to be a blank database. 但是,本地数据库中的任何数据都没有迁移到heroku数据库,从而使其成为空白数据库。 If I go into the admin section and manually input a datapoint, it appears on my site, so I know that database is correctly serving data. 如果我进入管理部分并手动输入数据点,该数据点将显示在我的站点上,因此我知道数据库正在正确地提供数据。 What is the proper way for migrating data from your local database to your online, heroku version of the database? 将数据从本地数据库迁移到数据库的在线Heroku版本的正确方法是什么? I thought the following code would migrate the data: 我认为以下代码将迁移数据:

heroku run python manage.py makemigrations
heroku run python manage.py migrate

But apparently I'm missing something. 但是显然我缺少了一些东西。

make migrations will create a migration that contains your schema, but no data. make迁移将创建一个包含您的架构但没有数据的迁移。 The migrate command applies the migration to the database. migrate命令将迁移应用于数据库。

In order to provide data to be sent over as part of the migrate command you need to either create a data migration or use a fixture . 为了提供作为迁移命令一部分发送的数据,您需要创建数据迁移或使用固定装置

Another option you have is to dump your local database and do an import into Heroku Postgres 您还有另一个选择是转储本地数据库导入Heroku Postgres

All in all, it depends on how much local data you have that you want copied over. 总而言之,这取决于要复制多少本地数据。 If its only a few rows, I would use either a data migration or a fixture, if its 100s or 1000s of rows an export/import of your dataset is your best bet. 如果只有几行,那么我将使用数据迁移或固定装置,如果有100或1000的行,则最好选择数据集的导出/导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM