Forum: Ruby on Rails add_index() naming error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
B3d3e763b80f4bbabadde8fe207e0d4f?d=identicon&s=25 Wiliam Langshaw (Guest)
on 2007-01-23 20:53
(Received via mailing list)
So I upgraded to Rails 1.2.1 and off the bat did a

> rake db:migrate VERSION=0

to start all fresh and clean.

Right away it failed in my first migration's down() method, because it
couldnt find the index in remove_index().

I got into my MySQL DB and sure enough the indexes were there.  Long
story short, I looked at:


And there is an obvious change in the way the method "index_name" works
to generate the index name to either add or remove depending on your

In a nutshell:

Rails 1.1.6: remove_index :users, :email -> looks for an index named
Rails 1.2.1: remove_index :users, :email -> looks for an index named

So of course Rails 1.2.1 isnt going to find this index, because it was
created with Rails 1.1.6.

Now, this is one thing. But looking through the ActiveRecord CHANGELOG,
there is NO mention of this, much less a way to fix it without manually
going into all my migrations and specifying the name of the index by
hand (rather than having Rails try to auto-generate the index name).

Is there something I am missing here?
10c122532c00465b809dbf9dc35806a7?d=identicon&s=25 Paolo Negri (Guest)
on 2007-01-24 11:35
(Received via mailing list)
I looked at this change because I was interested as well.

 Revision 4768, 11.1 kB (checked in by bitsweat, 5 months ago)

"Make indexed columns easy to extract from the index name. Oracle
users should explicitly assign index names due to field length
restrictions. "

In the same commit nothing was added to manage the "old style" indexes
so I think you have to work around it or check the commit after that.
Maybe you can just wrap the remove_index in a method that rescue the
exception if the index is not found and retries generating the old
style index.

This topic is locked and can not be replied to.