Skip to content

Using South to Migrate Django Models

Dyland Xue edited this page Apr 12, 2014 · 9 revisions

Initial Setup (Local)

  1. Pull from github master. git pull origin master
  2. Delete your database and create a new one -- important, don't try to be smart, just do it! (In PSQL, run DROP DATABASE dbname; CREATE DATABASE dbname;)
  3. Create the initial database. ./manage.py syncdb [--settings=settings.dev]
  4. Tell south where the current database is in migration history. At the time of this writing, the number is 0002. ./manage.py migrate nice 0002 --fake [--settings=settings.dev]

NOTE: Maxim had trouble doing migrate --fake to 0002. Instead, he saw Not synced (use migrations): - nice in syncdb output, so the right migrate command to run is python manage.py nice [--settings=settings.dev].

Workflow

Pulling

  1. Pull from github master. git pull origin master
  2. Sync other (non-south) tables in the database. ./manage.py syncdb [--settings=settings.dev]
  3. Migrate. ./manage.py migrate nice [--settings=settings.dev]

Modifying Django Models

  1. Before modifying anything, pull from github and migrate (see Pulling)
  2. Modify models as needed.
  3. Tell South of your modifications. This will add new python files to nice/migrations. ./manage.py schemamigration nice --auto [--settings=settings.dev]
  4. Apply your migrations. ./manage.py migrate nice [--settings=settings.dev]
  5. Push to server - this won't do anything to heroku. git push origin master

Updating Production Environment (Heroku)

  1. Update your models locally (see Modifying Django Models)
  2. Push to heroku. git push heroku master
  3. Apply the migration. !!SYNCDB FIRST!!

heroku run ./manage.py syncdb

heroku run ./manage.py migrate nice