Django Heroku 错误“您的模型具有尚未反映在迁移中的更改"; [英] Django Heroku Error "Your models have changes that are not yet reflected in a migration"

查看:15
本文介绍了Django Heroku 错误“您的模型具有尚未反映在迁移中的更改";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently added a model to my app (UserProfile) and when I pushed the changes to Heroku, I think I accidentally ran heroku run python manage.py makemigrations. Now when I try to run heroku run python manage.py migrate I get the error below

(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.

我该如何解决这个问题?请帮忙!

How do I fix this? Please help!

推荐答案

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

You need to first create the migrations locally, add them to your repository, commit the files with the new migrations and then push to 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

这篇关于Django Heroku 错误“您的模型具有尚未反映在迁移中的更改";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆