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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
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. On Wed, Nov 10, 2010 at 10:23 AM, Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com> wrote:> 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. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2010-Nov-10 21:05 UTC
Re: [feature request] Migrations and index (make the API for creating table more consistent with changing table)
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 <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. On 10-11-2010 18:27, Andrew Kaspick wrote:> 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. > > On Wed, Nov 10, 2010 at 10:23 AM, Rodrigo Rosenfeld Rosas > <rr.rosas@gmail.com> wrote: >> 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.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Prem Sichanugrist
2010-Nov-11 02:58 UTC
Re: [feature request] Migrations and index (make the API for creating table more consistent with changing table)
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 On 11 พ.ย. 2553, at 4:05, Rodrigo Rosenfeld Rosas wrote:> 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 <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. > > On 10-11-2010 18:27, Andrew Kaspick wrote: >> 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. >> >> On Wed, Nov 10, 2010 at 10:23 AM, Rodrigo Rosenfeld Rosas >> <rr.rosas@gmail.com> wrote: >>> 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. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Rodrigo Rosenfeld Rosas
2010-Nov-11 09:07 UTC
Re: [feature request] Migrations and index (make the API for creating table more consistent with changing table)
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. On 11-11-2010 00:58, Prem Sichanugrist wrote:> 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 > > On 11 พ.ย. 2553, at 4:05, Rodrigo Rosenfeld Rosas wrote: > >> 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<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. >> >> On 10-11-2010 18:27, Andrew Kaspick wrote: >>> 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. >>> >>> On Wed, Nov 10, 2010 at 10:23 AM, Rodrigo Rosenfeld Rosas >>> <rr.rosas@gmail.com> wrote: >>>> 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. >>-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.