4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Macでrails-ERD を使った ER 図 の作成法

Last updated at Posted at 2019-09-08

はじめに

現在、作成しているアプリで、rails-ERDによるER図を作成したので、その方法を備忘録として残します。これを使用することでデータモデルの構造や関係性を示したER図(Entity Relationship Diagram)が自動作成され、以下のようなPDFファイルを作成することができます。

スクリーンショット 2019-09-08 10.12.27.png

前提条件

  • ER図の作成対象となるアプリが作成されており、モデル作成とリレーション設定が済んでいること
  • Graphviz(グラフビズ)がインストールされていること

ER図作成の流れ

1.Gemfileの変更

Gemfile.

group :development do
  gem 'rails-erd'  #追記
end

2.rails-erd のインストール

ターミナル.
$ bundle install --path vendor/bundle

3.ER図の作成

ターミナル.
$ bundle exec erd

Gemfile等と同じ階層にerd.pdfが作成されていればOKです。

おまけ

今回が初めてrails-erdを使用したので当然Graphvizはインストールされてませんでした。その状態でbundle exec erdを実行すると怒られたのでGraphvizをインストールしました。

ターミナル.
$ bundle exec erd
Failed: RuntimeError: Saving diagram failed!
Verify that Graphviz is installed and in your path, or use filetype=dot.

$ brew install graphviz

作成したER図が他と一緒にコミットされないよう除外しました。

gitignore.
<中略>

erd.pdf #追記

参考

https://www.sejuku.net/blog/66196
https://tech.mof-mof.co.jp/blog/try-rails-erd.html

4
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?