Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if there is an index on a column through Rails console?

Let's say I do Image.column_names and that shows all the columns such as post_id but how do I check if post_id has an index on it?

like image 565
CodeCrack Avatar asked Feb 07 '15 20:02

CodeCrack


1 Answers

There is an index_exists? method on one of the ActiveRecord "connection adapters" classes.

You can use it like this:

ActiveRecord::Migration.connection.index_exists? :images, :post_id 
like image 100
Sunil D. Avatar answered Sep 28 '22 06:09

Sunil D.