【问题标题】:Django South - Unable to Reset App MigrationsDjango South - 无法重置应用程序迁移
【发布时间】:2013-06-23 17:33:26
【问题描述】:

我正在尝试重置我的南迁移历史记录,但无法为 myapp 运行迁移。我的 settings.py 是:

...
'south',
'myapp',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'payments',

不幸的是,我尝试过的方法对我不起作用:

  1. 删除/rm 所有现有的迁移文件
  2. 注释掉除南之外的所有内容
  3. 运行初始同步数据库
  4. 为每个应用运行./manage.py schemamigration app_name --initial
  5. 然后逐个迁移应用

此过程适用于除 myapp 之外的所有内容。当我尝试为 myapp 进行初始迁移时,我得到:

hostMigrations: 
! These migrations are in the database but not on disk:
<myapp: 0002_..._>
! I'm not trusting myself; either fix this yourself by fiddling
! with the south_migrationhistory table, or pass --delete-ghost-migrations
! to South to have it delete ALL of these records (this may not be good).

如果我通过 --delete-ghost-migrations 那么它告诉我没有什么可以迁移到 myapp,显然不是这样。当我 --fake 0002 它告诉我在 0002 之后没有其他东西可以迁移。还有其他方法可以解决这个问题吗?

【问题讨论】:

    标签: django postgresql django-south database-migration


    【解决方案1】:

    要完全删除迁移历史记录,您需要删除数据库表中的每一行。

    转到您的数据库并删除south_migrationhistory 表中的所有行:

    delete from south_migrationhistory;
    

    或者,如果您只想重置特定应用的历史记录,您可以这样做:

    delete from south_migrationhistory where app_name='your_app_name';
    

    希望这会有所帮助!

    【讨论】:

    • 出于好奇,--delete-ghost-migrations 在这种情况下会做同样的事情吗?
    • 我认为它的作用不止于此,这就是它产生上述错误的原因。我曾多次重置迁移,这是我完全重置完全控制的最直接的方法。
    • 你可能是对的,但我只会做delete from south_migration_history where app_name='myapp',所以我不必运行其他迁移并再次陷入其他麻烦:)。如果我错了,请纠正我
    • 你说得对,我只是假设他想要完全重置。这确实只会重置应用程序的迁移。我会在我的回答中纠正它。感谢您的反馈。
    • Paulo,谢谢,但删除 south_migrationhistory 表并不能解决 myapp 的“无迁移”问题。只有初始的 myapp 0001 迁移出现,但有 [00]13. south 正在认识到我的其他项目应用程序的额外迁移 - 我可以做些什么让它忽略 myapp 的?
    猜你喜欢
    • 2012-04-26
    • 2012-03-03
    • 2013-05-23
    • 1970-01-01
    • 2011-03-11
    • 2014-08-11
    • 2012-08-06
    • 2012-08-13
    • 1970-01-01
    相关资源
    最近更新 更多