Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "unconvert" an app from South (Django)?

I changed a lot in my models.py, including deleting a lot of fields, and renaming a couple of classes. schemamigration --auto worked fine, but trying migrate threw a bunch of errors.

All my code is currently in development so I don't mind too much losing the data. So I want South to "unconvert" or "unmanage" an app so I can rebuild all the tables with syncdb again.

Or I could delete all migration list and do schemamigration --initial again.

like image 768
hobbes3 Avatar asked Mar 12 '12 16:03

hobbes3


1 Answers

Yes, just delete the migrations and run schemamigration --initial again. You should do that anyways as normal course before moving to production. If you've already gone to production at least once, don't delete all the migrations -- just the ones you've created in the current development cycle and then run schemamigration --auto to get just one migration instead of the potential multiple ones.

FWIW, to "unconvert" an app using South, you merely delete the "migrations" directory, but in this scenario, there's no need.

UPDATE

It was pointed out that if you have already migrated your app, and you delete all the migrations and generate a single new one, South will complain about migrations still in the database. The actual process you should follow is:

  1. Rollback to the just before the newest migration you created in the current development cycle. For instance, if you were already at 0005 and you created three new migrations for the development work you were doing (now at 0008), you would rollback to 0005. If all of the migrations are new, you rollback to zero:

    python manage.py migrate yourapp zero
    
  2. Delete all of the migrations you're going to merge. In the above example, that would be 0006, 0007, and 0008, or for a new app, everything in the migrations directory but __init__.py.

  3. Generate a new migration to cover the ones you just deleted. If it's a new app, use --initial, or if it was a pre-existing app, use --auto.

    python manage.py schemamigration --initial yourapp
    
  4. Migrate

    python manage.py migrate yourapp
    
like image 163
Chris Pratt Avatar answered Nov 04 '22 02:11

Chris Pratt