SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

Visualizing database schema

Written in Ruby on Rails
updated on 10 Jan 2023

As you create and run migrations onto your database, different tables are created, and some tables might be connected to others via belongs_to and has_many.

As a beginner, it might be hard to keep track of the current state of your database.

One way to understand the current state of your database is to look at db/schema.rb, like this following example where we have the relationship of an author has many books:
language=>ruby ActiveRecord::Schema.define(version: 20161214031618) do create_table "authors", force: :cascade do |t| t.string "name" t.string "location" t.string "birth_year" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "books", force: :cascade do |t| t.string "name" t.string "publishing_year" t.integer "num_of_pages" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "author_id" end end
You can see that books and authors are related via author_id.

Now, there's a tool you can use to better visualize this database schema: dbdiagram.io.

You can go to dbdiagram.io, and click on "Create your diagram":
  1. Click Import → From Rails (schema.rb)
  2. Paste (or upload) your schema.rb
  3. Done!


For future projects, you can use this tool to better visualize your database schema, especially when it gets complex.

Trusted by

Students and instructors from world-class organizations

Imperial College London
Carnegie Mellon University
City University of Hong Kong
Hack Reactor
Cisco Meraki
University of Oxford
Swift
Bazaarvoice
Waterloo
Uber
AtlanTech
Tumblr
Boston College
Bombardier Aerospace
University of St. Andrews
New York University
Minerva Schools at KGI
Merrill Lynch
Riot Games
JP Morgan
Morgan Stanley
Advanced Placement®
Google
KPMG
The University of Hong Kong
University of Toronto
SCMP
Moat
Zynga
Hello Toby
Deloitte
Goldman Sachs
Yahoo
HSBC
General Assembly
Tesla
McGill University
Microsoft

Join the upcoming Cohort #102

Enroll for June 2nd, 2025