Django - view sql query without publishing migrations

Solution 1:

Use the sqlmigrate command from manage.py.

python manage.py sqlmigrate <appname> <migration number eg. 0001 or 0004>

will display the SQL statements for a specific migration of the app.

Solution 2:

Django does not provide that option. You can always create the migration, run sqlmigrate, and delete the migration file. As long as it isn't applied with migrate, nothing will happen.

Solution 3:

Run

python manage.py sql <appname>

-- Prints the CREATE TABLE SQL statements for the given app name(s).

python manage.py sqlall <appname>

-- Prints the CREATE TABLE and initial-data SQL statements for the given app name(s).

You'll find detail documentation here. https://docs.djangoproject.com/en/1.8/ref/django-admin/