Skip to content

Instantly share code, notes, and snippets.

@yeazin
Last active November 30, 2021 05:38
Show Gist options
  • Save yeazin/b3523e6a986a94c6ba3339509971957d to your computer and use it in GitHub Desktop.
Save yeazin/b3523e6a986a94c6ba3339509971957d to your computer and use it in GitHub Desktop.
Generating ERD for Django Applications

Generate ERD from Django Models


Install Dependicies

Installing django extensions

  #for windows
  pip install django-extensions
  # for mac/linux
  pip3 install django-extensions

Installing Grapviz in your maching

  #for windows
  pip install graphviz
  # for mac/linux
  pip3 install graphviz

Add django extensions in settings.py

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

Add the following Code anywhere in settings.py

  GRAPH_MODELS = {
    'all_applications' : True,
    'group_model' : True ,
}

Create the .dot output and convert to .png

  # windows
  python manage.py graph_models -a > output.dot
  # mac / linux
  python3 manage.py graph_models -a > output.dot

Then create the PNG file

  dot -Tpng output.dot -o output.png

or You can create the PDF file also

  dot -Tpng output.dot -o output.pdf

@yeazin
Copy link
Author

yeazin commented Sep 24, 2021

Do you have any Query?
join me then

Linkedin : yeazin
facebook : yeazin
email : naz.yeasin@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment