LoginSignup
9
6

More than 5 years have passed since last update.

railsのmodelにindexが貼ってあるかどうかを確認する方法

Last updated at Posted at 2016-05-18

modelが多いとindex貼ってあるのかな?って思い、調べることがありました。

sqlでも調べることができますが、railsでも調べることができます。

モデル名.connection.index_exists?(:テーブル名, :カラム名)

Blogモデルのuser_idにindexがあるのかどうかの確認です。

Blog.connection.index_exists?(:blogs, :user_id)

mysqlの場合はモデルの一覧で表示してくれるので、sqlで調べる方がいいかもしれません。

9
6
0

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
9
6