django migrations code example

Example 1: django make migrations

$ python3 manage.py makemigrations
$ python3 manage.py migrate

Example 2: how to create migrations in django

//to create migration files
python manage.py makemigrations

//to migrate migration files
python manage.py migrate

Example 3: fake migration

# This command allows us to disable all migrations made to the db 
# (usually done before deleting the migration files and wiping the database of all its data)
python manage.py migrate --fake

Example 4: django create empty migration

./manage.py makemigrations <app-name> --empty
./manage.py makemigrations --empty

Example 5: Your models have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

$ python manage.py makemigrations && python manage.py migrate
$ git add --all
$ git commit -m "fixed migrate error"
$ git push heroku master
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
--- Done ___

Example 6: django migrate fake zero

$ python manage.py migrate --fake YourApp zero
# This will Reverse all migerations in YourApp