【问题标题】:South 'nothing to migrate' message after successful schema migration模式迁移成功后的南“无迁移”消息
【发布时间】:2013-06-05 15:03:15
【问题描述】:

我有一个 Django 应用程序,我将 South 添加到其中,执行了一些迁移,并在我的本地计算机上按预期运行。但是,在将我的项目推送到 Heroku 之后,我除了数据库错误之外什么都没有。

在尝试处理我遇到的一个数据库错误时,我尝试了一项测试,删除了我的一个模型,将编辑后的模型文件推送到 Heroku 并运行:

heroku run python manage.py schemamigration django_app test_remove_pub --auto

这似乎工作正常。我回了消息:

Running `python manage.py schemamigration apricot_app test_remove_pub --auto` attached   
to terminal... up, run.6408
 - Deleted model django_app.Publication
 - Deleted M2M table for journalists on django_app.Publication
 - Deleted M2M table for tags on apricot_app.Publication
Created 0006_test_remove_pub.py. You can now apply this migration with: ./manage.py   
migrate django_app

因此,South 似乎完成了我所期望的一切 - 它删除了我的模型及其多对多关系并制作了适当的迁移文件。接下来,我输入:

 heroku run python manage.py migrate django_app

我回来了:

Running `python manage.py migrate django_app` attached to terminal... up, run.4792  
Running migrations for django_app:
- Nothing to migrate.
- Loading initial data for django_app.
Installed 0 object(s) from 0 fixture(s)

明明有东西要迁移,为什么还要说“没什么可迁移”??

【问题讨论】:

    标签: python django heroku django-south


    【解决方案1】:

    更改模型后,您需要做:

    heroku run python manage.py schemamigration django_app --auto
    

    如果有任何变化

    然后运行

    heroku run python manage.py migrate django_app
    

    South 根据以下数据库表中的条目应用迁移:south_migrationhistory。所以如果你想手动覆盖它,

    1. 删除您更改的模型的app_name 列中的所有条目
    2. 手动删除所有相关表。您可以通过在 django shell 中键入以下内容来获取所有表的列表:

      from django.db.models import get_app, get_models
      app = get_app(app_name)
      for model in get_models(app, include_auto_created=True):
          print model._meta.db_table
      
    3. 删除应用相关的migrations/文件夹

    4. 执行新迁移:./manage.py schemamigration app_name --initial
    5. 应用迁移./manage.py migrate app_name

    【讨论】:

      猜你喜欢
      • 2012-09-08
      • 1970-01-01
      • 2011-04-03
      • 2019-05-09
      • 2014-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多