开发者

Django convert Model to sql code

My plan is to be able to dynamically generate SQL tables. Since I know django can create SQL tables using models, they must have a function for this. The problem is I can not find this function in the Django folder, 开发者_如何学Cor maybe I simply don't recognize it. thnx


It's called django-admin.py

Start here: http://docs.djangoproject.com/en/dev/ref/django-admin/

Specifically, see http://docs.djangoproject.com/en/dev/ref/django-admin/#django-admin-sql


I am not exactly sure what you mean, but you can get the SQL for all the tables in an app by running this command: python manage.py sqlall your_app


If you're looking for the specific pieces of code, have a look at django.db.backends.base.creation to see how the sql is generated, of course there need to be individual implementations for different database types, so for example also see django.db.backends.postgresql_psycopg2.creation!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜