# Add\_index() naming error

**URL:** <https://www.ruby-forum.com/t/add-index-naming-error/83134>\
**Category:** Rails\
**Created:** [January 23, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/add-index-naming-error/83134 "2007-01-23T20:53:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wiliam\_Langshaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/c89c15/32.png) [@Wiliam\_Langshaw](https://www.ruby-forum.com/u/Wiliam_Langshaw)\
**Post date:** [January 23, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/add-index-naming-error/83134/1 "2007-01-23T20:53:04Z")

</div>

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:

vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/schema\_statements.rb

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  
context.

In a nutshell:

Rails 1.1.6: remove\_index :users, :email -\> looks for an index named  
“users\_email\_index”  
Rails 1.2.1: remove\_index :users, :email -\> looks for an index named  
“index\_users\_email”

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?

---

<div class="post-metadata">

**Author:** ![Wiliam\_Langshaw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/c89c15/32.png) [@Wiliam\_Langshaw](https://www.ruby-forum.com/u/Wiliam_Langshaw)\
**Post date:** [January 24, 2007, 11:35am UTC](https://www.ruby-forum.com/t/add-index-naming-error/83134/2 "2007-01-24T11:35:16Z")

</div>

I looked at this change because I was interested as well.

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

[http://dev.rubyonrails.org/changeset/4768](http://dev.rubyonrails.org/changeset/4768)

"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.

Paolo
