Prints the SQL for all migration django

Viewed 1892

I have django application, where I wanted to export all migration from my project , auth and admin to sql query. I am able to do

python manage.py sqlmigrate myapp 0001

However, I want to export all migration at same time rather than explicitly righting loops. Is there any package or tool that i can use for this.

2 Answers

you can use squashmigrations command

python manage.py squashmigrations <appname> <squashfrom> <squashto>

and press y

Delete all the before migration files

then run the following command

python manage.py sqlmigrate <appname> <squash_generated_migartion_file>

if you wanted to see the sql for auth migrations

python manage.py sqlmigrate auth 0001_initial

First make sure you are on directory with manage.py file i.e. project directory then, you can do

python manage.py makemigrations

and then run python manage.py migrate or python manage.py sqlmigrate

Related