[Fixed]-Generate Database Schema using Python

15πŸ‘

βœ…

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

πŸ‘€Thomas

5πŸ‘

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

πŸ‘€DrTyrsa

2πŸ‘

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?)

πŸ‘€jtpereyda

Leave a comment