南迁移痛苦地破碎了

时间:2012-01-28 23:02:34

标签: django django-models django-south

到目前为止,当我认为南方移民混乱时,南方移民运作良好。

我总是这样做:

manage.py schemamigration core --auto
manage.py migrate core

上次我更改了模型时,它很高兴地完成了模式迁移,但在第二步失败了。我已经再次执行了迁移核心(不知道为什么),但它抛出了同样的错误。然后,我会好的,我会改变别的东西并再次进行架构移植以使其恢复正常但这没有帮助,我现在卡住了:

D:\~Sasha\Portman>manage.py migrate --list

 core
  (*) 0001_initial
  (*) 0002_auto__del_field_project_is_active
  (*) 0003_auto__add_field_groups_description
  (*) 0004_auto__chg_field_project_name
  (*) 0005_auto__add_status__del_field_project_phase_indicator_resources__del_fie
  (*) 0006_auto__add_project_phase_history
  (*) 0007_auto__add_field_project_phase_project__del_field_project_project_phase
  (*) 0008_auto__chg_field_project_phase_date_end_plan
  (*) 0009_auto__del_field_project_phase_date_start_actual__del_field_project_pha
  (*) 0010_auto__del_status
  (*) 0011_auto__chg_field_project_phase_history_date_start_plan
  (*) 0012_auto__chg_field_project_link_business_idea__chg_field_project_link_cha
  (*) 0013_auto__del_field_project_project_sc_reviews
  (*) 0014_auto
  (*) 0015_auto__add_sc__del_field_sc_event_is_reviewed__del_field_sc_event_date_
  (*) 0016_auto__add_field_project_phase_is_finished
  (*) 0017_auto__del_field_project_phase_history_date_start_actual__del_field_pro
  (*) 0018_auto__del_field_project_phase_date_end_plan__del_field_project_phase_d
  (*) 0019_auto__add_field_project_phase_is_reviewed_by_pmo
  (*) 0020_auto__add_project_excel_import__add_priorities__add_field_project_is_i
  (*) 0021_auto__del_project_excel_import__add_project_imported_from_excel
  (*) 0022_auto__add_field_project_imported_from_excel_phase_date_end
  (*) 0023_auto__chg_field_project_imported_from_excel_date_end__chg_field_projec
  (*) 0024_auto__del_sc__add_sc_review_decision__add_sc_review_task__add_pmo_revi
  ( ) 0025_auto__chg_field_project_phase_phase_review_goal__chg_field_sc_review_t
  ( ) 0026_auto__del_field_project_phase_phase_review_goal__add_field_project_pha

...并尝试迁移0025引发同样的错误:

D:\~Sasha\Portman>manage.py migrate core 0025
 - Soft matched migration 0025 to 0025_auto__chg_field_project_phase_phase_review_goal__chg_field_sc_review_t.
Running migrations for core:
 - Migrating forwards to 0025_auto__chg_field_project_phase_phase_review_goal__chg_field_sc_review_t.
 > core:0025_auto__chg_field_project_phase_phase_review_goal__chg_field_sc_review_t
Traceback (most recent call last):
  File "D:\~Sasha\Portman\manage.py", line 11, in <module>
    execute_manager(settings)
  File "D:\install\python27\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
    utility.execute()
  File "D:\install\python27\lib\site-packages\django\core\management\__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\install\python27\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "D:\install\python27\lib\site-packages\django\core\management\base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "D:\install\python27\lib\site-packages\south\management\commands\migrate.py", line 102, in handle
    delete_ghosts = delete_ghosts,
  File "D:\install\python27\lib\site-packages\south\migration\__init__.py", line 202, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 215, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 284, in migrate_many
    result = self.migrate(migration, database)
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 121, in migrate
    result = self.run(migration)
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 95, in run
    return self.run_migration(migration)
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 77, in run_migration
    migration_function()
  File "D:\install\python27\lib\site-packages\south\migration\migrators.py", line 56, in <lambda>
    return (lambda: direction(orm))
  File "D:\~Sasha\Portman\core\migrations\0025_auto__chg_field_project_phase_phase_review_goal__chg_field_sc_review_t.py", line 12, in forwards
    db.rename_column('core_project_phase', 'phase_review_goal', 'phase_review_goal_id')
  File "D:\install\python27\lib\site-packages\south\db\sqlite3.py", line 128, in rename_column
    self._remake_table(table_name, renames={old: new})
  File "D:\install\python27\lib\site-packages\south\db\sqlite3.py", line 73, in _remake_table
    ", ".join(["%s %s" % (self.quote_name(cname), ctype) for cname, ctype in definitions.items()]),
  File "D:\install\python27\lib\site-packages\south\db\generic.py", line 134, in execute
    cursor.execute(sql, params)
  File "D:\install\python27\lib\site-packages\django\db\backends\util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "D:\install\python27\lib\site-packages\django\db\backends\sqlite3\base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: table "_south_new_core_project_phase" already exists

现在有办法解决这个问题吗? :(

2 个答案:

答案 0 :(得分:0)

实际上没有配方 - 看起来问题可能会在太多不同的条件下出现。在我的情况下,我最终删除了_south_new_core_project_phase表,并且南方已经重新创建并将其应用于两次丢失的迁移。

有时人们会这样做 - 进行迁移,但如果他们现有的表结构与模型中的对象(我的情况)不匹配,他们最终会丢失列错误,我希望尽可能避免这种情况。 / p>

答案 1 :(得分:0)

我看到如何解决此问题的唯一方法是手动获取数据库和模型,而不使用南方,然后创建全新的迁移。这是一个很好的解释:

What's the recommended approach to resetting migration history using Django South?