150👍
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.
9👍
These existing answers are not enough, as I found out trying to follow them. First detect and make the migration script for your app:
manage.py makemigrations app
Make note of the four-digit migration number which starts the filename. Then print the SQL with:
manage.py sqlmigrate app 0002 # <-- number here
When finished, remove the file before it gets run or committed:
rm app/migrations/0002_auto_8675309.py
- [Django]-How to put comments in Django templates?
- [Django]-Location of Django logs and errors
- [Django]-Access web server on VirtualBox/Vagrant machine from host browser?
6👍
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.
- [Django]-How to customize activate_url on django-allauth?
- [Django]-Django DRF with oAuth2 using DOT (django-oauth-toolkit)
- [Django]-Django aggregate or annotate
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/
- [Django]-Annotate with latest related object in Django
- [Django]-Function decorators with parameters on a class based view in Django
- [Django]-Inline in ModelForm