Hi, My tests(rspec) are failing on models that has a String primary key. Rails wrongly creates the test table with the primary key in Integer format. As a result, the fixtures can not be imported, nor does relationships match up. The database is imported and needs to match with an external database, so there is no possibly of changing the primary key to integer. Does anyone know how to force Rails to recreate the test tables to respect string primary keys? Another poster also experienced this problem, http://www.ruby-forum.com/topic/90740#new. But unfortunately he didn''t get a reply. Much thanks, Zac -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Zac Zheng wrote:> Hi, > > My tests(rspec) are failing on models that has a String primary key. > Rails wrongly creates the test table with the primary key in Integer > format. As a result, the fixtures can not be imported, nor does > relationships match up. > > The database is imported and needs to match with an external database, > so there is no possibly of changing the primary key to integer. > > Does anyone know how to force Rails to recreate the test tables to > respect string primary keys?This fix this turned out to be easy. Schema.rb is run to create the test tables. I edited my copy to the following: create_table "countries", :force => true, :id => false do |t| t.column "locode" # other columns end # Manually assign ''locode'' as primary key execute "ALTER TABLE `countries` ADD PRIMARY KEY (`locode`);" Hey Presto! My specs that use countries are now running. Thanks to http://www.ruby-forum.com/topic/113935#new Zac -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---