Using South on a Heroku-hosted Django Project
Problem: You need to add new fields to the admin of a Django project hosted on Heroku but don't want to destroy data by running syncdb on your Heroku-hosted database.
Solution: South
These instructions assume you're working in a clean checkout of a Heroku project named herokuproject, which contains a Django project named djangoproject, which contains an app named djangoapp. You need to add a new admin field to djangoapp.
- Open
settings.pyand add 'south' to your list ofINSTALLED_APPS - Run syncdb locally:
python django_project/manage.py syncdb - Convert your project to use South:
python django_project/manage.py convert_to_south django_app - Add some new fields to
django_project/django_app/models.py - Set up the schema:
python django_project/manage.py schemamigration django_app --auto - Perform the migration:
python django_project/manage.py migrate django_app - Add
SouthHeroku project'srequirements.txtfile. For example:South==0.7.3 - Add the South
django_project/migrationsdirectory to version control and commit all your changes. - Push your changes to Heroku:
git push heroku master - Run
syncdbon Heroku:heroku run bin/python django_project/manage.py syncdb - Convert your Heroku instance of
django_appto use Southheroku run bin/python django_project/manage.py convert_to_south django_app - Perform the migration:
heroku run bin/python django_project/manage.py migrate django_app
Note that you will have to repeat the django_app-specific steps for each Django app you modify.
And what if you make further changes to djangoproject/djangoapp/models.py?
- Make changes to
django_project/some_app/models.py - Create the south migration file:
python django_project/manage.py schemamigration some_app --auto - Migrate locally:
python django_project/manage.py migrate some_app - Commit your changes and push them to Heroku
- Migrate on Heroku:
heroku run bin/python django_project/manage.py migrate some_app
Gratitude to Casey Thomas for the South knowledge-sharing.