我最近在我的应用程序(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.
我该如何解决这个问题?请帮忙!
答案 0 :(得分:33)
您需要首先在本地创建迁移,将它们添加到您的存储库,使用新的迁移提交文件,然后推送到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
答案 1 :(得分:1)
$ python manage.py makemigrations && python manage.py migrate
$ git add --all
$ git commit -m "Fixed migrate error"
$ git push heroku master
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
您还肯定没有忽略
中的迁移路径.gitingnore
答案 2 :(得分:0)
听起来您在对模型进行了更改之后但在获得初始迁移文件之前运行了makemigrations
。尝试将应用恢复到添加新模型之前的状态,然后再次运行makemigrations
以创建初始迁移。然后重新添加您的更新并再次运行makemigrations
。这将创建从初始数据结构到新更新的数据结构的第二次迁移。然后尝试部署。
https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps