Search code examples
djangomigrationdjango-south

Marking South migrations as new


I accidentally ran faked South migrations for an app using the --fake option, but the database is missing the last change.

I faked three migrations, but the database state is still at 0002. If you list the migrations, all migrations are marked as run.

$ ./manage.py migrate cmsplugin_mailchimp --list

 cmsplugin_mailchimp
  (*) 0001_initial
  (*) 0002_thankyou_field
  (*) 0003_redirect_url

Is there a way to mark the latest migration as new, so that it gets processed when I run ./manage.py migrate cmsplugin_mailchimp?


Solution

  • There's no extra option to "mark a migration as new", but there is a different, quite obvious solution: Simply do a backwards migration.

    $ ./manage.py migrate cmsplugin_mailchimp 0002 --fake
    
     - Soft matched migration 0002 to 0002_thankyou_field.
    Running migrations for cmsplugin_mailchimp:
     - Migrating backwards to just after 0002_thankyou_field.
     < cmsplugin_mailchimp:0003_redirect_url
       (faked)
    
    $ ./manage.py migrate cmsplugin_mailchimp --list
    
     cmsplugin_mailchimp
      (*) 0001_initial
      (*) 0002_thankyou_field
      ( ) 0003_redirect_url
    

    Now the state of South matches the state of the database, and you can actually run the last migration::

    $ ./manage.py migrate cmsplugin_mailchimp
    
    Running migrations for cmsplugin_mailchimp:
     - Migrating forwards to 0003_redirect_url.
     > cmsplugin_mailchimp:0003_redirect_url
     - Loading initial data for cmsplugin_mailchimp.
    Installed 0 object(s) from 0 fixture(s)