This project is archived and is in readonly mode.

#5645 ✓resolved
Tim Connor

Rails 3.0.0 add_index fails silently on invalid index names

Reported by Tim Connor | September 17th, 2010 @ 04:08 AM

If add_index is called with a name that is too long, the migration appears to be successful but the index is not created.

The error is very easy to reproduce. Create a new rails project, then run the following migration. After execution the table will be created but the index will not.

class TestOfAddIndex < ActiveRecord::Migration
  def self.up
    create_table :blah do |t|
      t.string :name
    end
    add_index :blah, [:name], :name => "a really long name that is too long for the database to handle and should cause an error"
  end
  def self.down
  end
end

The output of the migration is:

$ rake db:migrate
(in /Volumes/projects/rails/add_index_test)
==  TestOfAddIndex: migrating =================================================
-- create_table(:blah)
   -> 0.0016s
-- add_index(:blah, [:name], {:name=>"a really long name that is too long for the database to handle and should cause an error"})
   -> 0.0002s
==  TestOfAddIndex: migrated (0.0020s) ========================================

And the resulting schema.rb is:

ActiveRecord::Schema.define(:version => 20100917024939) do
  create_table "blah", :force => true do |t|
    t.string "name"
  end
end

I have attached a patch that will fix the problem.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages