Help us understand the problem. What is going on with this article?

【Rails】ER図作成

RailsでER図を作成する便利なライブラリのインストールと使い方

必要な各ライブラリをインストール

  • rails-erd 【gem】
  • graphviz

必要なのはこの2つ
※ homebrewが必要なので事前にインストール

rails-erdのインストール

Gemfileに追記

Gemfile
group :development do
...
  gem "rails-erd" # 追加
...
end

できたら下記コマンドでインストール

$ bundle install

graphvizのインストール

$ brew install graphviz

これで必要なライブラリのインストールは終わり

ER図出力

下記コマンドを使用するとカレントディレクトリにerd.dotファイルが生成される

$ bundle exec erd --inheritance --direct --attributes=foreign_keys,content --filetype=dot

dotファイルを閲覧できる形式に変換

  • pngに変換
$ dot -Tpng erd.dot -o erd.png
  • pdfに変換
$ dot -Tpdf erd.dot -o erd.pdf
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away