2

South migrations have worked quite well until now when I think it got mixed.

I always do:

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

Last time I changed my model it has happily done the schemamigration but failed at the second step. I have executed migrate core again (not sure why) but it has thrown the same error. I then though ok, I'll change something else and do the schemamigration again to get this back on track but this hasn't helped and I'm now stuck:

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

... and trying to migrate the 0025 fires the same error:

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

Is there a way to fix this now? :(

abolotnov
  • 4,282
  • 9
  • 56
  • 88

2 Answers2

0

There is really no recipe - looks like the issue can pop out at too many different conditions. In my case, I ended up removing _south_new_core_project_phase table and south has re-created and applied it for both missing migrations.

Sometimes people will do --fake migration but if their existing table structure does not match the object in the model (my case), they will end up with missing columns error and I wanted to avoid that as much as possible.

abolotnov
  • 4,282
  • 9
  • 56
  • 88
0

The only way I've seen how to fix this is to manually get the database and models in sync without using south and then create brand new migrations. Here's a good explanation:

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

Community
  • 1
  • 1
Spike
  • 5,040
  • 5
  • 32
  • 47
  • It's not the only way to do this but one of possible options when your models are small and you are able to manually track the changes. – abolotnov Jan 29 '12 at 19:59