Free tool

Turn a Rails schema.rb into an ER diagram

Paste db/schema.rb and get the database it records as DBML: every create_table, index, and add_foreign_key. 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 is read from schema.rb

  • Each create_table block is a table, with the id primary key Rails adds unless the block says id: false, names another type such as id: :uuid, or sets primary_key:.
  • Each t.<type> line is a column: t.string a varchar, t.datetime a timestamp, t.jsonb a jsonb, with null: false kept.
  • Each t.index is an index, keeping its name. A unique index on one column is shown as a unique column.
  • Each add_foreign_key is a relationship line between the two tables.

The schema as it is, not as the code describes it

This is the useful difference between reading schema.rb and reading the models. A model can declare belongs_to :user for years without anyone adding the constraint, and the diagram drawn from schema.rb will show that table standing alone. Paste the result into the schema checker to list tables with no relationships and foreign keys with no index.

Working from another stack? There are the same converters for Django models and Prisma schemas.

Rails ER diagram questions

How do I make an ER diagram of a Rails app?

Paste db/schema.rb above to get it as DBML, then paste the DBML into a DB Planner project. No gem is added to the app and nothing runs against your database.

Why schema.rb and not the models?

Rails regenerates schema.rb from the database after every migration, so it lists the tables, columns, indexes, and foreign keys that actually exist. A model file says belongs_to; schema.rb says whether the foreign key is really there.

Why are some relationships missing from the diagram?

Only add_foreign_key statements become relationships. A belongs_to with no database constraint is a convention in Ruby, not a foreign key, so schema.rb has no line for it. That gap is often worth knowing about.

Does it work with structure.sql?

structure.sql is plain SQL, so use the SQL to DBML converter for it. It reads PostgreSQL, MySQL, and SQL Server.

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