Django’s South application

South enables easy migration of code changes to Django that is independent of database layer. Some userful commands used for migration:

Create a migration file

python manage.py schemamigration appName --auto

Migrate the newly created changes into Django (All pending migration changes shall be applied to the project)

python manage.py migrate

Undo migration – this takes 2 steps. Firstly, migrate to an older version of Migration ID script. This would roll back the migration scripts invoked after that. Then you can physically delete the migration scripts post that ID.

manage.py migrate appName migrationIdToMigrateTo
//Delete all migration scripts after migrationId that you reverted to. 
//e.g. if you reverted to ID 30, then delete all migration scripts from 31 onwards

Handling migration conflicts while working in teams
I ran into a problem where one of my team mates and I created a migration at the same time which resulted in creating 2 migration files with same numbers:
0016_migration_name_1
0016_migration_name_2

And after running manage.py migrate, the system would throw out errors saying that one migration was run out of place from the second where it shouldn’t have been. And the system wouldn’t allow me to go back to migration 0015. This is what I had to do to fix it:

1. python manage.py migrate –merge
#This would apply both migrations even if out of order
2. Undo migration and go back to migration number 0015
3. Re-create the migration scripts by running schemamigration
4. Execute manage.py migrate to execute the new migrations

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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