Django - view sql query without posting transfer

When I make changes to some models, I want to see the SQL that django will run to implement these changes to the database.

The usual way to do this is to make a "makemigrations appname". This will result in the migration, for example, "0001_someName.py". Then you can execute 'sqlmigrate 0001_someName.py'

But I want to look at sql directly, without creating intermediate migration. It can be done?

+6
source share
3 answers
python manage.py sqlmigrate <appname> <migration no eg. 0001 or 0004> 

this will lead to a certain application migration. But if you want to show all sql for a specific application, use this:

 python manage.py sqlmigrate <appname> 
+10
source

Django does not provide this option. You can always create a migration, run sqlmigrate and delete the migration file. Until it is applied with migrate , nothing will happen.

+3
source

Run

 python manage.py sql <appname> 

- Prints SQL CREATE TABLE statements for the specified application names.

 python manage.py sqlall <appname> 

- prints CREATE TABLE statements and SQL source data queries for the specified application names.

Here you will find detailed documentation. https://docs.djangoproject.com/en/1.8/ref/django-admin/

+2
source

Source: https://habr.com/ru/post/984150/


All Articles