Federico
2011-Apr-19 21:13 UTC
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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Apr-20 07:39 UTC
Re: Composite index via command line migration, different behaviour in file
On 19 Apr 2011, at 22:13, Federico <federico.rota01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Federico Rota
2011-Apr-20 19:30 UTC
Re: Composite index via command line migration, different behaviour in file
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. Il giorno 20/apr/2011, alle ore 09:39, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> ha scritto:> > > On 19 Apr 2011, at 22:13, Federico <federico.rota01-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.