Free tool

Turn Django models into an ER diagram

Paste a models.py and get the tables Django creates for it as DBML, including the ones it creates without being asked. Paste that into DB Planner and it is an ER diagram.

Free, no account. Your schema is converted on our server and not stored. Up to 200 KB.

What Django writes for you, made visible

A Django model is a description of a table with several things left unsaid. The converter says them:

  • The primary key. Every model gets an auto-incrementing id unless a field sets primary_key=True.
  • The foreign key column. author = models.ForeignKey(Author, ...) is the column author_id in the database, with a reference to the other table’s key. OneToOneField works the same way.
  • The delete rule. on_delete=models.CASCADE, SET_NULL, PROTECT, and the rest are carried onto the reference.
  • The join table. A ManyToManyField becomes the table Django creates behind it, with a foreign key to each side.
  • The lengths Django assumes. An EmailField is a varchar(254) and a SlugField a varchar(50) unless you say otherwise.

Abstract models are skipped, since they create no table of their own.

A diagram the whole team can read

Not everyone who needs to understand the data model reads Python. Once the models are a diagram in DB Planner, a product manager or an analyst can follow the relationships, leave notes on tables, and review a change before it becomes a migration. The schema checker will also tell you which foreign keys have no index, which Django adds for you but hand-written SQL often does not.

Django ER diagram questions

How do I generate an ER diagram from Django models?

Paste your models.py above to get the tables as DBML, then paste the DBML into a DB Planner project to see them as a diagram. Nothing has to be installed in the Django project.

Why is there an id column I did not write?

Django adds an auto-incrementing id primary key to every model that does not declare one with primary_key=True. The database has that column, so the diagram shows it.

How is a ManyToManyField shown?

As the join table Django creates for it, with a foreign key to each side. That table exists in the database even though no class in models.py describes it.

Why do the table names not have my app prefix?

Django names a table app_model, but a pasted models.py does not say which app it belongs to. A model with db_table in its Meta uses that name exactly; the others use the lowercased class name, which is easy to rename in the DBML.

Put your schema on the board

Start on the free plan, no card needed. Pro is $5 a month when you outgrow it.

Start designing free