Django South Notes


South is “a tool to provide consistent, easy-to-use and database-agnostic migrations for Django applications.” However, as South’s website says, since Django 1.7 now has its own migrations tool South has been deprecated. I personally think the new Django migrations are a little bit better.

However we still use South at FiveStars and I thought other people who still use South might appreciate these notes.

See list of migrations (asterisks means already applied)

$ ./ migrate --list [app name]

Apply latest migrations

$ ./ migrate [app name]

Fake migration

$ ./ migrate [app name] [version #] --fake

Migrate backwards

$ ./ migrate [app name] [version #]

Migrate back to zero state, i.e. nothing

$ ./ migrate [app name] zero

Create first migration

$ ./ schemamigration [app name] --initial

Create subsequent migrations

$ ./ schemamigration [app name] —-auto

Create empty schema migration

$ ./ schemamigration [app name] —-empty [migration name]

Create data migration

$ ./ datamigration [app name] [migration name]

Review migration history

select * from south_migrationhistory order by applied;

Redo migrations that have been hand edited

Sometimes you will find someone followed the bad practice of hand editing a migration after it has been committed. For example they’ll add another column. Because you have already run the migration you may not notice this until many migrations later when something breaks because of this missing column.

To fix this:

  1. Fake migration backwards to the edited migration
  2. Migrate back one before the edited migration
  3. Migrate forward one for the edited migration
  4. Fake migrate forwards the rest until you get to your current state
  5. Migrate the migration that previously was giving problems

Leave a Reply

Your email address will not be published. Required fields are marked *