Django Heroku Error “Your models have changes that are not yet reflected in a migration”

旧城冷巷雨未停 提交于 2019-11-29 12:06:21

问题


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!


回答1:


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.

The sequence is something like this:

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



回答2:


  1. Make migrations locally
$ python manage.py makemigrations && python manage.py migrate
  1. Commit changes and push it on the server
$ git add --all
$ git commit -m "Fixed migrate error"
$ git push heroku master
  1. Now make migrations on the server
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate

You have also be sûre that you did'nt ignore that migrations path in your

.gitingnore



回答3:


It sounds like you ran makemigrations after you made changes to your model but before you had an initial migration file. Try to revert your app to the state it was before you added the new model and run makemigrations again to create the initial migration. Then add your updates back in and run makemigrations once more. This will create a second migration from your initial data structure to the new updated one. Then try your deployment.

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



来源:https://stackoverflow.com/questions/28598676/django-heroku-error-your-models-have-changes-that-are-not-yet-reflected-in-a-mi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!