Generating ERD for Django Applications

Generating an ERD (Entity Relationship Diagram) can be helpful to understand what your database looks like, and is also really easy to generate if you’re running a Python/Django Application.

Step 1: Install django-extensions and graphviz

 pip install django-extensions && pip install graphviz

Step 2: Add django_extensions to settings.py

INSTALLED_APPS = [
    ...
    'django_extensions',
    ...
]

Step 3 Create the .dot output and convert to .png

Run manage.py graph_models from the environment you may normally use:

python manage.py graph_models -a > output.dot

From your mac, change the format to png using graphviz

brew install graphviz
dot -Tpng output.dot -o output.png

References
Django Extensions graph_models docs
Django Extensions Commands Unavailable?
Opening .dot files on mac

Leave a Reply

Your email address will not be published. Required fields are marked *