Remove_index appends suffix "_index" to the given name!

Hi all

This creates an index with the name position_and_produkt_id_uniq:
add_index :bilder, [:produkt_id, :position], :unique => true, :name =>
:position_and_produkt_id_uniq

This should remove the same one:
remove_index :bilder, :position_and_produkt_id_uniq

Sadly I get the following error:
Mysql::Error: Can’t DROP ‘bilder_position_and_produkt_id_uniq_index’;
check that column/key exists: DROP INDEX
bilder_position_and_produkt_id_uniq_index ON bilder

Why does Rails append the suffix _index to the given name?? And how can
I prevent it?

Thanks,
Josh

Josh,

This creates an index with the name position_and_produkt_id_uniq:
add_index :bilder, …:name => :position_and_produkt_id_uniq
This should remove the same one:
remove_index :bilder, :position_and_produkt_id_uniq

You forgot the ':name => ’ part :

remove_index :bilder, :name => ‘position_and_produkt_id_uniq’

Alain

Ah, thank you.

Anyway, do I need to remove this index explicitly?

def self.down
remove_index :bilder, :name => :position_and_produkt_id_uniq
remove_column :bilder, :position
end

Because (at least with MySQL) it is destroyed automatically because one
of its corresponding fields (position) is deleted…

Joshua

Anyway, do I need to remove this index explicitly?

It doesn’t hurt.

Because (at least with MySQL) it is destroyed automatically because
one
of its corresponding fields (position) is deleted…

As I don’t know how other DB managers work (today), or could work in
the future, I wouldn’t take that risk.

Alain