On 19 Apr 2011, at 22:13, Federico <[email protected]> wrote:

> Hello everybody,
> I have a class like this:
> 
> class Foos < ActiveRecord::Migration
>  def self.up
>    create_table :foos,:id => false, do |t|
>      t.references :table1
>      t.references :table2
>      t.timestamps
>    end
>  end
> 
>  def self.down
>    drop_table :foos
>  end
> end
> 
> I would like to add a composite index on the 2 columns :table1
> and :table2 but the command
> rails generate migration add_index(:foos,
> [:table1_id, :table2_id], :unique => true)
> 
> fails with the following output:
>    Missing type for attribute '='.
> Example: '=:string' where string is the type.
> 
> If I edit the up method of Foos like this:
> 
>  def self.up
>    create_table :foos,:id => false, do |t|
>      t.references :table1
>      t.references :table2
>      t.timestamps
>    end
>    add_index(:foos, [:table1_id, :table2_id], :unique => true)
>  end
> 
> then the index is successfully created.
> I can't understand why. I would like to create this composite index
> with a migration from command line.
> 

As far as I know there just isn't a command line shortcut for creating such a 
migration - create a blank one with

rails g migration AddAnIndexToFoos

And add your call to add_index in there. 

Fred
> Thanks
> 
> Federico
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to