Skip to content

Generate ER diagram of database

Rasmus Rudling edited this page Nov 10, 2021 · 2 revisions

Django extension: Graph model To generate an ER-diagram we use the Django extension. https://django-extensions.readthedocs.io/en/latest/graph_models.html

A quite good instruction is found here: https://medium.com/@yathomasi1/1-using-django-extensions-to-visualize-the-database-diagram-in- django-application-c5fa7e710e16

Inside the virtual environment (after vagrant ssh): sudo apt install python-pygraphviz sudo apt install pkg-config To export to png directly: pip install django-extensions pygraphviz

Add django extensions to your installed apps in the ais/common/settings.py file: INSTALLED_APPS = [ ... 'django-extensions', ]

Generate a png file of all apps: python manage.py graph_models -a -g -o filename.png

Generate a dot file of app X (sucha as banquet, companies, people etc.): python manage.py graph_models X -o filename.png

If you have trouble with pygraphviz install pydot instead and generate .dot files: pip install pyparsing pydot

Generate a dot file of all apps: python manage.py graph_models -a > filename.dot

Generate a dot file of app X (sucha as banquet, companies, people etc.): python manage.py graph_models X > filename.dot

Can also include several apps in one file: python manage.py graph_models X Y > filename.dot

Enter the python shell: python manage.py shell

The run the following python script:

>>> import pydot
>>> (graph,) = pydot.graph_from_dot_file('filename.dot')
>>> graph.write_png('filename.png')

Exit the python shell with: >>> exit()

Now you have a .dot file and a .png file in your AIS repo’s root.

Clone this wiki locally