Generating ERD for Django models

About ERD


  • ER Diagram stands for Entity Relationship Diagram
  • It displays the relationship of entity sets stored in a database
  • It helps to explain the logical structure of database
  • ER diagrams are created based on three basic concepts: entities, attributes and relationship

Generating using Django extension


Django extension provides an option to generate ERD diagrams of the DB models

The following are steps to do so

  • Install system level dependencies
  • Following is an example command to install in Ubuntu:
  • apt-get install -y python3-dev graphviz libgraphviz-dev pkg-config
  • Install python library:
  • pip install pygraphviz
  • You have to specify the Django apps to generate the diagram.
  • Either you can use -a argument to generate for all apps else specify apps in the command OR can choose to create settings for this in Django settings.py to persist the requirement
  • Now the ER diagram can be generated by using the following command, run the command inside Django project directory: ./manage.py graph_models

Sample


To show you the sample ER diagram, I have used the following Django stub project: https://github.com/shacker/gtd and a library called "django-todo"

That altogether brings a Django project of a Todo app which has features like multi-user and group.
Sample command, I used
./manage.py graph_models -a --output=<DOCS_BUILD_DIR>/django-models.png
 

Here is the ER diagram of the project. Click on the image to view clearly










More information: Graph models — django-extensions 3.1.2 documentation

Post a Comment

1 Comments

  1. For the past few months, my focus has been on increasing the efficiency of Django models. Fortunately, I'm getting help from experts of PhD Dissertation Writing Services as well as technical bloggers like you.

    ReplyDelete