🍡 Django - Migrations
Updated at 2017-02-21 00:48
- Create the model class to
app_name/models/
. - Import the model class in
app_name/models/__init__.py
if it exists. - Then use the following commands.
# creates a migration files for missing model definitions
python manage.py makemigrations app_name --name model_name_plural
# show the list of migrations
python manage.py showmigrations app_name
# show the SQL this migration would run
python manage.py sqlmigrate app_name 0666
# migrate
python manage.py migrate
# rollback to this migration
python manage.py migrate app_name 0665
# remove all migrations
python manage.py migrate app_name zero
# migrate all back
python manage.py migrate app_name