Change and Migrate Django Models using South

South is a very handy django application to manage the django models. If we are developing web projects using django we need to change the Django model several times , In normal case we have to do these changes manually by editing both django model and backend database appropriately. This is very frustrating if we have to do it several times.

The South application makes it very easy to handle the model changes and fill the initial data into the database tables. To setup the South application along with your django project, you need to do very simple changes to the file of your django project. To make it simple you have to do this step before adding any of your django apps to the project.

First of all install the south application to your system.

#easy_install south

then you have to add your south app to django file under

INSTALLED_APPS variable, ie;

# Uncomment the next line to enable the admin:
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'south', # <---HERE

Now we added the south app to our django project, the commands associated with this app comes under the

Next step is to sync all models to the backend database, for that you have to use the usual method , ie;

Migrate all tables to backend database,
it includes our south apps tables.

$python syncdb

That's it !. we are now ready to use south app for our apps model management.

Currently we added tables of default django apps and south app to backend. Now we are ready to add our applications to the django project. After adding new django application to the INSTALLED_APPS variable, we need to migrate it's models using south management commands,

Initially you have to add new app under south , for that,
python schemamigration your_app --initial
This will setup your app under south, need to run only once,
Then migrate models to backend database,

$python migrate your_app

After the initial addition of your django app under south, to migrate the future model changes under the same app, you have to do the bellow steps,

After any changes to your model,
First detect those changes ,

$python schemamigration your_app --auto

Then Migrate to backend,

$python migrate your_app

So using south app you are now managed model changes without touching backend database. In this manner we can manage all django applications under your project.

Try this out ! and save your time.

Go Top