-
Notifications
You must be signed in to change notification settings - Fork 0
South tutorial
We decided we will each maintain our own migrations and push the models.
To start off, you will have to delete all migrations that might be in the south_migrationhistory table (because they are not your migrations) and apply an initial migration of your own. If you don't have south installed, install it with "pip install south".
Assuming you have south installed, here are the steps you need to follow to get started:
1.Delete all migrations from south_migrationhistory
./manage.py dbshell
sqlite> DELETE FROM south_migrationhistory;
2.Delete all files in the app/migrations/ folder
3.Run syncdb
./manage.py syncdb
4.Create an initial migration
./manage.py schemamigration app --initial
This creates the python code that creates all the tables that you have.
5.Since you already have the tables, you don't want to create them again. So you need to apply the first migration with the --fake option.
./manage.py migrate app --fake
This makes everything make sense from south's perspective. It adds the migration to south_migrationhistory, but doesn't actually create the tables. Since the tables are already there, it's as if south had created them with the python code generated in step 4.
Now everything should be set up, and this is how you can make other changes:
a) Add the field (or make any other changes) on models.py and save the file.
b) ./manage.py schemamigration app --auto
This creates a migration in app/migrations - that is, python code that adds the field without losing records (the function forwards) and python code that removes the new field - the function backwards (to take you from the new state back to the previous state)
c) ./manage.py migrate app
This calls the forwards() function of the new migrations (so it applies the changes)
That should be almost all that we'll need for now. Check south documentation for more advanced stuff. (i.e: how to call the backwards() function, how to change migrations manually etc.) http://south.readthedocs.org/