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

4ngedf3f  于 11个月前  发布在  Go
关注(0)|答案(5)|浏览(288)

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

字符串
我该如何解决此问题?救命啊!

20jt8wwn

20jt8wwn1#

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

字符串

q1qsirdb

q1qsirdb2#

1.本地迁移

$ python manage.py makemigrations && python manage.py migrate

字符串

2.提交更改并推送到服务器

$ git add --all

x

$ git commit -m "Fixed migrate error"
$ git push heroku master

的字符串

3.现在在服务器上运行migrate

$ heroku run python manage.py migrate


您还需要确保在.gitingnore文件中没有忽略这些migration paths

0yycz8jy

0yycz8jy3#

回答我的案例:

your_field=models.CharField(max_length=9,default=False)

字符串
转换为

your_field=models.CharField(max_length=9,default='False')


我的例子:在www.example.com中models.py,我想将字段的默认值设置为False。第一个默认值= False我的合约没有''。但是在运行python manage.py migrate之后,我得到了上面的错误。在''中放置False后,问题得到解决。
有时候,字段模型中的默认值必须是False字符串类型。

default = False


如果在模型中编写,您将遇到此错误。
事实上,根据我们拥有的字段类型,我们不能总是将模型中字段的默认值设置为TrueFalse。必须转换为CharField类型的字符串。

unguejic

unguejic4#

听起来像是在对模型进行更改之后运行了makemigrations,但在初始迁移文件之前。尝试将应用恢复到添加新模型之前的状态,然后再次运行makemigrations以创建初始迁移。然后重新添加更新并再次运行makemigrations。这将创建从初始数据结构到新的更新数据结构的第二次迁移。然后尝试部署。
https://docs.djangoproject.com/en/1.7/topics/migrations/#adding-migrations-to-apps

mjqavswn

mjqavswn5#

迁移到heroku是一个糟糕的想法,最好的做法总是在本地迁移,然后推到heroku。但如果你发现自己在这个混乱尝试恢复到最初的迁移在heroku '不本地'即运行“heroku运行manage.py 0001_initial“它为我至少工程

相关问题