Change - South

Created on Sept. 6, 2012, 12:37 p.m. by Hevok & updated on Feb. 5, 2013, 3:27 p.m. by Hevok

South enables schema and data migration of a django-backend database ¶
[http://www.djangopro.com/2011/01/django-database-migration-tool-south-explained/]. ¶
Migrations should be version-controlled ¶
[http://stackoverflow.com/questions/10083130/what-is-the-correct-way-to-deal-with-db-migration-while-using-south-django-and]. ¶


Adding South
------------ ¶

In order to add South to Django project, development & production do the ¶
following [http://stackoverflow.com/questions/4035296/adding-south-to-django-project-development-production]: :: ¶
$ ./manage.py snycdb ¶
$ ./manage.py convert_to_south myproject.myapp ¶
$ ./manage.py schemamigration myproject.myapp --auto # Change models ¶
$ ./manage.py migrate myproject.myapp # Alternatively to get a fresh Django database with existing South migrations


sync all tables and perform fake migration [http://www.troeger.eu/cms/?p=317]: :: ¶
$ ./manage.py syncdb --all ¶
$ ./manage.py migrate --fake ¶

If required south can be resetted ¶
[http://lincolnloop.com/blog/2011/jun/20/resetting-your-south-migrations/; https://groups.google.com/forum/?fromgroups#!topic/south-users/PxEskcnkibc[1-25]; https://groups.google.com/forum/#!msg/south-users/iIQT8ZWs2cI/GQ4kONoT5Q4J[1-25]]. ¶


Migration ¶
--------- ¶
South's DB Content reflects the state of the DB, while migration files reflect the state of the source code. ¶

The schemamigration --auto commadn created migration files from the models.py, but it is possible to tweak them if necessary. If they were tweaked then the changes need to be saved somewhere. ¶

The migrate command compares migration files with DB Content. Thus if mgration files are moved with the source code to the serer, where there are previous souht DB Content it will apply precisley all the migrations needed to bring the DB in sync with the source code.


Migrate through the history ¶
--------------------------- ¶

To go back in forward in the south migration history simply define the migration to move: :: ¶

$ ./manage.py migrate <appname> 0005 ¶


Renaming a Django App ¶
--------------------- ¶

South allows to rename a django app, through some manual steps are required [http://stackoverflow.com/questions/4566978/renaming-an-app-with-django-and-south]. ¶

A step-by-step example of renaming django app, managed by South migration history is described here: https://github.com/ASKBOT/django-south-app-rename-example ¶


Moving a Model from one App to another ¶
-------------------------------------- ¶

Moving models between apps is straightforward ¶
[http://stackoverflow.com/questions/1258130/how-do-i-migrate-a-model-out-of-one-django-app-and-into-a-new-one]: :: ¶

$ ./manage.py schemamigration specific create_cat --auto ¶
$ ./manage.py schemamigraiion common drop_cat --auto ¶


Listing Migrations ¶
------------------ ¶
To list all migrations without actually running them execute this: :: ¶

./manage.py migrate --list

Parent: Web Framework Web Framework

Comment: Added migration section/

Comment on This Data Unit