335π
You need to figure out the number of the migration just before the one you want to roll back.
Your app should have a migrations directory, with files in it named like
0000_initial.py
0001_added_some_fields.py
0002_added_some_more_fields.py
0003_deleted_some_stuff.py
Normally, when you run ./manage.py migrate your_app
, South runs all new migrations, in order. (It looks at the database tables to decide which ones are βnewβ).
However, you can also specify any migration by number, and South will migrate your database, either forward or backward, to take it to that point. So, with the example files above, if you have already migrated up to 0003, and you wanted to run 0003 in reverse (undoing it, effectively), you would run
./manage.py migrate your_app 0002
South would look at the database, realise that it has run 0003 already, and determine that it has to run the reverse migration for 0003 in order to get back to 0002.
219π
Just in case someone (like me) wondered how to migrate back from initial (0001):
django-admin.py migrate some_app zero
output:
Running migrations for some_app:
- Migrating backwards to zero state.
< some_app:0001_initial
βzeroβ is a special state before any migration.
Reference: http://south.aeracode.org/docs/commands.html
- [Django]-Django Rest Framework model serializer with out unique together validation
- [Django]-Django 1.5b1: executing django-admin.py causes "No module named settings" error
- [Django]-How do I install psycopg2 for Python 3.x?
3π
Add a migration name at the end of the parameters:
./manage.py migrate app-name 00xx-migration-name
- [Django]-Django create userprofile if does not exist
- [Django]-How to mix queryset results?
- [Django]-Django Rest Framework pagination extremely slow count