Django Plugins — Django South for Database Migrations


Database migrations handled easily. Now I can add the migration files that are generated to the GIT repository PER-BRANCH and grab them on the production server when the time comes.

UPDATE 9 months later when I realized this is one of the top results for django south.

I might as well write a simple tutorial on how to use it. Read the South docs, but in as few lines of code as possible, here’s what to do:

pip install South

### modify and add 'south' to INSTALLED_APPS

python syncdb 
# adds south tables

python schemamigration myapp --initial
# sets up your app for the first migration.

python migrate myapp --fake 
# "fakes" a migration because you will get an error if you try to migrate
# from an existing database setup. You will get a "table already exists" error otherwise.

### modify your app models, then auto-create a migration

python schemamigration myapp --auto
# this will auto detect the changes

python migrate myapp
# will apply new migration.

git add myapp/migrations/ 
# add migrations to version control

### download migrations on remote machine, and simply type in 
python migrate
# note: this is after faking the first migration if the database exists.

Hope that helps!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s