manage.py sql command for django models - Django

空扰寡人 提交于 2019-12-10 19:26:30

问题


just wondering... but is it possible to generate SQL commands for django's models?

e.g. the session model

python manage.py sql django

Any ideas?


回答1:


You need to mention the name of the specific app that comes with django, such as

 python manage.py sql auth
 python manage.py sql admin

I find it a bit clumsy that you can't give fully-qualified names (such as django.contrib.auth), but using just the last part of the name seems to work fine.




回答2:


This is no longer possible with django migrations (django>=1.7). The sql management command is no longer available.

Though it operates slightly differently, the sqlmigrate management command can be used to find the sql commands for individual migrations.

./manage.py sqlmigrate auth  0001
./manage.py sqlmigrate auth  0002
...


来源:https://stackoverflow.com/questions/4246363/manage-py-sql-command-for-django-models-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!