Migrations and index problem

According to Rails API, it is possible to write something like:

create_table :my_table do |t|
     t.string :login
     t.index :login, unique: true
end

But I'm getting the following error:

undefined method `index' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x00000000efd7d8>

Is this a bug or is the API outdated? Or maybe, I'm doing something wrong...

Thanks in advance,

Rodrigo.

P.S: I'm testing in SQLite3.

This is a question for
http://groups.google.com/group/rubyonrails-talk/topics, not core.

hint: Define you index after the table is created. Use a change_table block.

Hi Andrew,

I know there is the rails-talk list and I've actually posted there last week about my new gem rails-web-console:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/20be1c5b39700d03/4ade31c542b6480f?lnk=gst&q=rails-web-console#4ade31c542b6480f

What happened is that I overlooked the migration guides and didn't note that the syntax is only valid while changing a table. Sorry for the confusion, but I would like to take this opportunity to ask why this syntax cannot be used for creating table as well.

I think it is much cleaner than using the old (actually current too) syntax "add_index" after the table creation block.

Is that difficult to achieve?

Sorry for any confusion. I hope this is the correct list to discuss that new feature (I've even changed the message subject).

Rodrigo.

Hi,

In early days I have several confusion on t.index too. As far as my knowledge go, I feel that some database engine doesn't support inline index creation so that this is the only way to do it?

- P

Hi Prem,

Even if the database doesn't support inline index creation, I guess AR migrations could defer the index creation on these situations without altering the syntax...

But I haven't taken a look at the source, so I'm not sure if it would be easy to implement such a feature...

Best regards,

Rodrigo.