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

Ben*_*Ben 13 python django heroku django-1.7 django-migrations

我最近在我的应用程序(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.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?请帮忙!

Bur*_*lid 36

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


ged*_*lod 8

  1. 在本地进行迁移
$ python manage.py makemigrations && python manage.py migrate
Run Code Online (Sandbox Code Playgroud)
  1. 提交更改并将其推送到服务器上
$ git add --all
Run Code Online (Sandbox Code Playgroud)
$ git commit -m "Fixed migrate error"
Run Code Online (Sandbox Code Playgroud)
$ git push heroku master
Run Code Online (Sandbox Code Playgroud)
  1. 现在在服务器上进行迁移
$ heroku run python manage.py makemigrations
Run Code Online (Sandbox Code Playgroud)
$ heroku run python manage.py migrate
Run Code Online (Sandbox Code Playgroud)

您还必须确信您没有忽略您的迁移路径

.gitingnore
Run Code Online (Sandbox Code Playgroud)

  • 您永远不需要在 heroku 服务器上进行迁移。您应该始终在本地进行迁移,然后推送到服务器。您应该只需要在服务器上迁移。 (2认同)