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