SQL to ER Diagram
Home › Django

Django to ER Diagram

Visualize your Django models as an interactive ER diagram. Paste models.py as it is — fields, ForeignKey, OneToOneField, ManyToManyField and abstract base models are read directly — or paste the SQL from sqlmigrate for the exact database tables.

Open the diagram tool →
No signup · nothing uploaded · export PNG / SVG / Mermaid / DBML · shareable link
ER diagram of the Django example schema: Author and Post (2 tables, 1 relationship)
The Django example below, drawn by the tool: Author and Post (2 tables, 1 relationship).

At a glance

What it is
SQL to ER Diagram is a free, open-source browser tool that turns Django models into an interactive entity-relationship (ER) diagram.
Input
A Django models.py (fields, ForeignKey, OneToOneField, ManyToManyField, abstract base models), or the SQL that sqlmigrate prints.
Output
An interactive ER diagram you can rearrange, then export as PNG, SVG, Mermaid, DBML or PlantUML, or share as a link.
Cost
Free. MIT-licensed open source. No account or signup.
Privacy
Runs entirely in your browser. The schema is never uploaded, and share links carry the diagram in the URL fragment, which is not sent to a server.
Limits
It never connects to your database itself: you paste schema text, or run one read-only catalog query in your own client and paste the result. There are no accounts, so there is no real-time multi-user editing; diagrams are kept in your browser, as a saved file, or as a share link. Layout stays smooth at around 300 tables.

How it works

  1. Copy your models.py — one app or several pasted together.
  2. Paste it into the editor (or drop the .py file on the page). Django is detected automatically.
  3. Each model becomes a table with Django’s implicit id; ForeignKey and OneToOneField become foreign keys and ManyToManyField becomes a junction table.
  4. Arrange, hide tables, then export PNG/SVG or convert to Mermaid/DBML.

Example

Paste Django models like these:

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100)

class Post(models.Model):
    title = models.CharField(max_length=200)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)

…and you get Author and Post with a relation from Post.author_id → Author.id. Try it with your own →

Guide

Django doesn't have a schema file to paste — your models live in Python — but it can print the exact SQL it will run, and that's what you paste here. Run python manage.py sqlmigrate yourapp 0001 for the initial migration (or sqlmigrate on whichever migration created the tables you care about) and copy the output: CREATE TABLE "blog_post" with an REFERENCES "blog_author"("id") foreign key, ready to diagram.

Tips for multi-app projects:

The result reflects the real database Django creates — including the id BIGINT PRIMARY KEY auto-pk and _id column naming — so it's accurate even when your models use custom db_table or related_name tricks.

Why use it

DjangoSQLSQLAlchemyPostgreSQL

FAQ

How do I make an ER diagram from Django models?

Paste your models.py into the editor. Each model becomes a table, and ForeignKey, OneToOneField and ManyToManyField become relations.

Can I see all apps at once?

Yes. Paste the models from several apps together — relations written as "app.Model" are linked by the model name.

Are the table names the real database names?

A model that sets db_table in its Meta is shown under that name. Otherwise the table is labelled with the model class name (Post), because Django’s default app_post name depends on the app label, which models.py doesn’t contain. For the exact tables, paste the output of python manage.py sqlmigrate yourapp 0001 instead.

Is my schema uploaded anywhere?

No. Everything runs locally in your browser — your schema is never uploaded to or stored on any server.

Is it free?

Yes. It is completely free and open source, with no account or sign-up required.

Related