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 heroku_project
, which contains a Django project named django_project
, which contains an app named django_app
. You need to add a new admin field to django_app
.
Open
settings.py
and 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
South
Heroku project’srequirements.txt
file. For example:South==0.7.3
Add the South
django_project/migrations
directory to version control and commit all your changes.Push your changes to Heroku:
git push heroku master
Run
syncdb
on Heroku:heroku run bin/python django_project/manage.py syncdb
Convert your Heroku instance of
django_app
to 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 django_project/django_app/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.