【问题标题】:Django Heroku Error "Your models have changes that are not yet reflected in a migration"Django Heroku 错误“您的模型具有尚未反映在迁移中的更改”
【发布时间】:2015-04-20 08:14:15
【问题描述】:

我最近向我的应用程序 (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.

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

【问题讨论】:

  • 我猜到了,因为我改变了 INSTALLED_APPS 的顺序。我看不出其他原因,但

标签: python django heroku django-1.7 django-migrations


【解决方案1】:
  1. 在本地进行迁移
$ python manage.py makemigrations && python manage.py migrate
  1. 提交更改并将其推送到服务器上
$ git add --all
$ git commit -m "Fixed migrate error"
$ git push heroku master
  1. 现在在服务器上运行迁移
$ heroku run python manage.py migrate

您还需要确保您没有忽略 .gitingnore 文件中的这些迁移路径

【讨论】:

  • 你永远不需要在 heroku 服务器上进行迁移。您应该始终在本地进行迁移,然后再推送到服务器。你应该只需要在服务器上迁移。
  • 你的权利亲爱的@Shahar Gino
【解决方案2】:

听起来您在对模型进行更改之后但在获得初始迁移文件之前运行了makemigrations。尝试将您的应用恢复到添加新模型之前的状态并再次运行 makemigrations 以创建初始迁移。然后重新添加您的更新并再次运行makemigrations。这将创建从初始数据结构到新更新数据结构的第二次迁移。然后尝试您的部署。

https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

【讨论】:

【解决方案3】:

您需要首先在本地创建迁移,将它们添加到您的存储库,使用新迁移提交文件,然后推送到 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

【讨论】:

  • 首先 - 感谢大家尝试帮助我。现在,我的本地环境是最新的,并且可以按预期工作。当我运行git status 时,它说我的文件是最新的,当我运行git push heroku master 时它说一切都是最新的。然而,当我运行heroku run python manage.py migrate 时,我收到错误消息“您的模型具有尚未反映在迁移中的更改”,正如我所描述的。还有什么其他想法或建议可以让我解决问题吗?
  • 看来您的存储库不同步;你有任何未跟踪的文件吗?
  • 如果你指的是我的 .gitignore 文件,它是这个 github.com/github/gitignore/blob/master/Python.gitignore 的副本,没有任何额外内容
  • 我在 heroku 中删除了我的应用程序,但是当我重新添加它时,我仍然遇到同样的错误!有没有机会请你帮我解决这个问题?
  • 你得到了什么:git ls-files . --exclude-standard --others
猜你喜欢
  • 2017-01-19
  • 1970-01-01
  • 2018-03-22
  • 2022-12-10
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 2021-07-19
  • 2020-12-01
相关资源
最近更新 更多