Free tool

Turn a Prisma schema into an ER diagram

Paste a schema.prisma and get the database it describes as DBML: real table and column names, native types, and every relation as a reference. 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.

How a Prisma schema maps to tables

  • A model is a table, named by @@map when it has one and by the model name otherwise.
  • A scalar field is a column, named by @map when present. @id becomes the primary key, @unique a unique constraint, a ? a nullable column, and @default(autoincrement()) an auto-incrementing one.
  • Native types win. @db.VarChar(255) and @db.Uuid are the database’s own types, so they are used in place of the default a bare String would get.
  • A relation is a reference. @relation(fields: [authorId], references: [id]) becomes a foreign key from those columns, and its onDelete rule comes with it.
  • @@index becomes an index on the table.

Why draw a Prisma schema at all

A schema.prisma is easy to write and hard to see whole. Past twenty models the relations are scattered across the file, each one declared twice, and the question a new teammate has, what hangs off what, is not answered by reading top to bottom. A diagram answers it at a glance, and because it is drawn from the schema itself it cannot disagree with the code.

In DB Planner the same reader sits behind the Import dialog, and a schema.prisma in a GitHub repository can be linked to a project so the project is flagged when a push changes the file. To go the other way, the DBML to Prisma generator writes a schema from a design.

Prisma ER diagram questions

How do I get an ER diagram from a Prisma schema?

Paste the schema.prisma above to get it as DBML, then paste that DBML into a DB Planner project. Each model is drawn as a table card and each @relation as a line between the two columns it joins.

Does it use the database names or the Prisma names?

The database names. A model with @@map("users") becomes the table users, and a field with @map("created_at") becomes the column created_at, because the diagram is of the database Prisma talks to.

Why are some Prisma fields missing from the tables?

Relation fields are not columns. A field whose type is another model, or a list of one, is Prisma’s view of a foreign key that already exists as a scalar field beside it, so it becomes the relationship line and not a second column.

Can I go from a diagram back to a Prisma schema?

Yes. The DBML to Prisma generator on this site writes a schema.prisma from DBML or SQL, with relations on both sides and @@map names.

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