method
index
v3.2.13 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::Table
index(column_name, options = {})public
Adds a new index to the table. column_name can be a single Symbol, or an Array of Symbols. See SchemaStatements#add_index
Examples
Creating a simple index
t.index(:name)
Creating a unique index
t.index([:branch_id, :party_id], :unique => true)
Creating a named index
t.index([:branch_id, :party_id], :unique => true, :name => 'by_branch_party')
6Notes
Re: Doesn't work? Don't think it ever has.
Instead of
create_table :user_follows, :force => true do |t|
t.references :user
t.references :followed_user
t.timestamps
t.index :user
t.index :followed_user
end
Try
create_table :user_follows, :force => true do |t|
t.references :user
t.references :followed_user
t.timestamps
end
index :user_follows , :user
index :user_follows , :followed_user
It looks like the provided examples are incorrect...
still broken
add_index is a different method. I think this is just a bug and it's broken.
Doesn't work? Don't think it ever has.
This doesn't work for me. I do something like:
create_table :user_follows, :force => true do |t|
t.references :user
t.references :followed_user
t.timestamps
t.index :user
t.index :followed_user
end
and I get:
rake aborted!
An error has occurred, all later migrations canceled:
undefined method `index' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x106c02220>
add_index has the same effect.
Or maybe...
or maybe
add_index :user_follows , :user
add_index :user_follows , :followed_user
index doesn't work
@ssoroka even I'm having same issue. how did you resolve it?
This method does not work.
It's an old problem, reported back in 2010, just reopened issue: