Search code examples
djangodjango-southdatabase-migration

South, restore a DB with broken migrations


python manage.py migrate page --list

 page
  (*) 0001_initial
  (*) migrations from 0002 to 0006
  (*) 0007_auto__del_realestatelistcontext__del_homepagecontext__add_listcontext
  (*) 0008_auto__add_field_listcontext_num
  (*) 0009_auto__chg_field_listcontext_content
  (*) 0010_auto__del_field_listcontext_content
  ( ) 0011_auto__add_field_listcontext_content

I messed up things so that both python manage.py migrate page 0009 and python manage.py migrate page 0011 raise DatadaseError.

I'm not interested to fix the broken migrations, but I want to restore the DB back to migration 0008 (I'm able to manually change the Python model as it was in 0008). I'm new to South and seeking suggestions on how to do that.


Solution

  • If you can manually restore the database state to 0008, you can tell South to treat it as such by "faking" the reverse migration to 0008.

    python manage.py migrate page 0008 --fake
    

    This will set the internal state to say the last applied migration is 0008 without trying to actually apply the reverse migrations for 0010 and 0009.