开发者

Generate Database Schema using Python

I want to generate a basic DB schema for my django project to display all my Apps with Models and Model Fields with boundary conditions etc. Is there already any DB schema generator for django in pytho开发者_StackOverflow社区n? Or otherwise how should i go about doing it.


If your talking about needing to see the SQL schema, run ./manage.py sqlall <appname>

If you want a visualisation of the schema you can get django-extensions and run ./manage.py graph_models -a -g -o my_project.png. This will produce a pretty schema graph for you, but generally omits border conditions. you may want to check the options to add more data. http://readthedocs.org/docs/django-extensions/en/latest/graph_models.html


manage.py sql <appname appname ...> (docs)


Using Your DB

As mentioned in the tutorial, you can use your database's command line client to get the schema.

Example using sqlite:

python manage.py dbshell
> .schema

You may need to install sqlite3 for this to work.

Using Django

You used to be able to use python manage.py sql ..., but it has been deprecated in 1.9 in favor of migrations. You can check out the initial migration scripts using:

python manage.py sqlmigrate myapp 0001_initial

(From Answer: Equivalent of sqlall in Django 1.9?)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜