Skip to content

Instantly share code, notes, and snippets.

@kra3
Last active December 23, 2015 11:01
Show Gist options
  • Save kra3/6625499 to your computer and use it in GitHub Desktop.
Save kra3/6625499 to your computer and use it in GitHub Desktop.
Django south demystified
# Install and south to your django app
pip install south
# Add south to INSTALLED_APPS list of settings.py
vi settings.py
#-------------------------------------------
# A syncdb will create required south tables (now on only use `migrate` command)
python manage.py syncdb
## PS: (migration) generations are kept in a `/migrate/` sub directory of apps and are simple python files.
#-------------------------------------------
## Case 1 : You have an existing app (with models are created in db & probably some data)
# On your dev PC
# this will create migration file for initial generation, and also to create the migrationhistory entry.
python manage.py convert_to_south app_name
# On other places: check out code (hope you have migrations from previous step committed into repository)
# this will create the migrationhistory without changing the database schema.
python manage.py migrate app_name 0001 --fake
## Case 2 : You are just starting development
# do use --initial option to create a migration file for first generation.
python manage.py schemamigration app_name --initial
## Case 3 : After you made some changes to your model; provided you already done initial migration and applied it
# do use --auto option to create a generation file for your changes
# PS: migrations are chained, so you need all your previous migrations. So don't delete any
python manage.py schemamigration app_name --auto
#-------------------------------------------
# To apply a migration (ie., to alter your db schema)
python manage.py migrate app_name
## Notes:
# To list all migrations (and whether they applied or not)
python manage.py migrate --list
# To remove migration history from db (keeps migration files)
python manage.py migrate my_app_name zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment