Composite index via command line migration, different behaviour in file

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.

Thanks

Federico

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 Fred, at least I'll stop bouncing my head against the wall trying to make my command work!
I'll stick with your solution or mine.