Django Heroku 错误“您的模型有尚未反映在迁移中的更改”

新手上路,请多包涵

我最近向我的应用程序 (UserProfile) 添加了一个模型,当我将更改推送到 Heroku 时,我想我不小心运行了 heroku run python manage.py makemigrations 。现在,当我尝试运行 heroku run python manage.py migrate 时,出现以下错误

(leaguemaster) benjamins-mbp-2:leaguemaster Ben$ heroku run python manage.py migrate
Running `python manage.py migrate` attached to terminal... up, run.1357
Operations to perform:
  Synchronize unmigrated apps: allauth
  Apply all migrations: auth, admin, socialaccount, sites, accounts, account, contenttypes, sessions, leagueapp
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
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.

我该如何解决?请帮忙!

原文由 Ben 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 865
1 个回答

您需要首先在本地创建迁移,将它们添加到您的存储库,使用新迁移提交文件,然后推送到 heroku。

序列是这样的:

 1. (add/modify some someapp/models.py)
2. python manage.py makemigrations someapp
3. python manage.py migrate
4. git add someapp/migrations/*.py (to add the new migration file)
5. git commit -m "added migration for app someapp"
6. git push heroku
7. heroku run python manage.py migrate

原文由 Burhan Khalid 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题