This project is archived and is in readonly mode.
ActiveRecord::ConnectionAdapters::Table#index does not generat indexes
Reported by Jarl Friis | March 3rd, 2010 @ 08:50 PM
When using the following syntax for creating indexes in a migration, no indexes are created:
create_table :properties do |t| t.string :namespace t.string :name t.string :value t.index [:namespace, :name], :unique => true end
However when I use
create_table :properties do |t| t.string :namespace t.string :name t.string :value end add_index :properties, [:namespace, :name], :unique => true
Things work fine.
This has been reproduced on both PostgreSQL and MySQL adapter.
for the discussion and confirmation.
Comments and changes to this ticket
The following applies to Rails 2.3.5....
This got me interested so I started to write up a patch and when
digging around in the source some more noticed that the only places
"t.index" is referenced is when referring to change_table() NOT create_table().
See line 533 of rails/activerecord/lib/active_record/
I compared this with the create_table stuff and there is a clear
So, I am thinking now that this isn't a bug, but perhaps is an over
sight that should be addressed so the two are more inline. But then
again there is a bunch of other stuff in the change_table() that isn't
Not sure how/if this helps, but perhaps it provides more background.
I observe (still in 2.3.5) that
change_tablealso suffers this problem. The below code will have no effect.
change_table :properties do |t| t.index [:namespace, :name], :unique => true end
#remove_index(in the self.down method) works! E.g. the below code has effect.
change_table :properties do |t| t.remove_index [:namespace, :name] end
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Tickets have moved to Github
The new ticket tracker is available at https://github.com/rails/rails/issues