ong-z
8/26/2015 - 4:33 AM

Django Migration Commands

Django Migration Commands

###################################
# 1.7 migrations
###################################

# create migration file
python manage.py makemigrations reebok

# make an empty migration file (for data migrations)
python manage.py makemigrations --empty yourappname

# apply migration 
python manage.py migrate

# unapply all migrations for myapp 
python manage.py migrate myapp zero

# apply migration to named number (may involve unapplying migrations if you have previously migrated past the named migration)
python manage.py migrate myapp 0004

# checks for problems in your project without making migrations or touching the database
python manage.py check

# squash migration (pass it the app label and migration name you want to squash up to)
python manage.py squashmigrations myapp 0004

###################################
# 1.6 migrations
###################################

# create tables and indexes for all of the models in the app (first time)
python manage.py schemamigration fiit --initial

# create tables and indexes for all of the models in the app (subsequent)
python manage.py schemamigration fiit --auto

# update most recent migration instead of creating new one
python manage.py schemamigration fiit --auto --update

# write migration to stdout instead of file
python manage.py schemamigration fiit --auto --stdout

# data migration
python manage.py datamigration fiit migration_name

# apply migration
python manage.py migrate fiit

# undo migration 002
python manage.py migrate fiit 0001