简体   繁体   English

Heroku 上的 Django - 向 postgreSQL 数据库添加新模型

[英]Django on Heroku - add new models to postgreSQL database

I have an Django 2.1 / Python 3.6 application running on Heroku's hobby account.我有一个在 Heroku 的爱好帐户上运行的 Django 2.1 / Python 3.6 应用程序。 The first version of this deployment went smoothly.此部署的第一个版本进行得很顺利。 Now I needed to add more fields to existing models and also add additional models from my local setup (which is running very smoothly with the changes) to Heroku.现在我需要向现有模型添加更多字段,还需要从我的本地设置(随着更改运行得非常顺利)向 Heroku 添加其他模型。 I do the usual我照常做

git push heroku master

to get the new code over to Heroku.将新代码移交给 Heroku。 Then I do both然后我都做

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

The first step gives me第一步给了我

Running python manage.py makemigrations on ⬢ hirt-family-v4... up, run.3753 (Free)
Migrations for 'users':
users/migrations/0005_auto_20190425_1452.py
- Create model XtraPhotos
- Add field phone_number to person
- Add field parent to xtraphotos

which is fine, but the migrate is also coming back with the message很好,但是迁移也会返回消息

Running python manage.py migrate on ⬢ hirt-family-v4... up, run.5929 (Free)


Operations to perform:


Apply all migrations: account, admin, auth, contenttypes, sessions, sites, users


Running migrations:


No migrations to apply.


Your models have changes that are not yet reflected in a migration, and so won't be applied.


 Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

I tried to go step by step, meaning I add each missing field one after the other, but this also leads to the essentially same problem.我试着一步一步来,这意味着我一个接一个地添加每个缺失的字段,但这也会导致本质上相同的问题。

Don't use heroku run to create the migration files.不要使用heroku run创建迁移文件。

  1. Run python manage.py makemigrations locally在本地运行python manage.py makemigrations
  2. Check-in the new migration files签入新的迁移文件
  3. Push changes to git将更改推送到 git
  4. Now, you can migrate your database with heroku run python manage.py migrate现在,您可以使用heroku run python manage.py migrate迁移您的数据库

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

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