Migrating an existing database to South on Gondor.io

  • Sun 29 July 2012

  • I'm learning Django. I'm learning A LOT! A part of that learning is making mistakes, making educated guesses and WTF were you thinking?! There comes a point where the project is far enough along, enough data exists, if you're messing with your models, you don't want to do a python manage.py app --reset on your database. At least for me I did it a few times, losing a couple of hours worth of work, and there came a point where I couldn't afford to lose anymore time. I had used South in the past, but I was told to not mess with it while starting out, so I stayed away from it. I knew at this point, I couldn't. I needed to undo a mistake and had to dig in. These are my notes from ~/.zshhistory so if I need to do this again, I can reference these. Though, going forward, I should setup all projects to use South (whether I leverage it or not). These steps also include that you've followed these setup instructions first.

    python manage.py schemamigration --initial press

    Initial South migration -- captures current state of app's model. This creates app/migrations/0001_initial.py

    $ git add --interactive
    $ git commit -m "starting south migration from scratch"

    Add/commit changes

    Deploy to Gondor with --no-on-deploy switch

    gondor deploy --no-on-deploy primary master

    Make changes to model (for my use, I needed to remove 'unique=True' from a field). After making changes to model, run South again:

    python manage.py schemamigration press --auto

    This creates file app/migrations/0002_auto__del_unique_page_pgnumber.py

    Again, Add/commit changes:

    $ git add --interactive
    $ git commit -m "schema migration to remove unique=True"

    Need to migrate the database on Gondor, data already exists, so we pass it --fake option

    $ gondor run primary manage.py migrate --fake press

    After having done the migration to South on Gondor, we can deploy to Gondor as we always have. Upon deploying, it runs the migrations, removing the 'unique=True' attribute on the model field and I'm back in business!

    $ gondor deploy primary master

    Comments !