Hi.... I''ve a table named software_cis. I need to change the type of the column ci_class in this table from string to integer. For this i generated a migration file named ChangeCiClassToInteger. class ChangeCiClassToInteger < ActiveRecord::Migration def self.up change_column :software_cis, :ci_class, :integer end def self.down raise ActiveRecord::IrreversibleMigration end end When i run the migration, it gets terminated and generates a message: rake aborted! RuntimeError: ERROR C42846 Mcannot cast type character varying to integer Fparse_expr.c L1533 Rtypecast_expression: UPDATE software_cis SET ci_class_ar_tmp = CAST(ci_class AS integer) Anyone please help to find the solution...... Regards Suneeta -- 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 -~----------~----~----~----~------~----~------~--~---
Try to specify the :limit and :default for the migration and run it again. Check for the rows that contain some string values in the column ci_class On Dec 28, 4:29 pm, Suneeta Km <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi.... > I''ve a table named software_cis. I need to change the type of the > column ci_class in this table from string to integer. For this i > generated a migration file named ChangeCiClassToInteger. > > class ChangeCiClassToInteger < ActiveRecord::Migration > def self.up > change_column :software_cis, :ci_class, :integer > end > > def self.down > raise ActiveRecord::IrreversibleMigration > end > end > > When i run the migration, it gets terminated and generates a message: > > rake aborted! > RuntimeError: ERROR C42846 Mcannot cast type character varying to > integer Fparse_expr.c L1533 Rtypecast_expression: UPDATE software_cis > SET ci_class_ar_tmp = CAST(ci_class AS integer) > > Anyone please help to find the solution...... > > Regards > Suneeta > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Kiran Soumya wrote:> Try to specify the :limit and :default for the migration and run it > again. > > Check for the rows that contain some string values in the column > ci_class > > > > On Dec 28, 4:29 pm, Suneeta Km <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>Still its not working.... Is it not possible to convert the column type from string to integer? -- 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 -~----------~----~----~----~------~----~------~--~---
On Dec 28, 2007, at 10:09 PM, Suneeta Km wrote:> Still its not working.... Is it not possible to convert the column > type > from string to integer?The original error you posted RuntimeError: ERROR C42846 Mcannot cast type character varying to integer Fparse_expr.c L1533 Rtypecast_expression: UPDATE software_cis SET ci_class_ar_tmp = CAST(ci_class AS integer) strongly suggests that there are values in the ci_class column that cannot be cast as integer. Either they are spaces, characters, or something. Most databases have some sort of IS_NUMERIC function you can use to verify the contents of the columns. In the database query tool that you use, run something like select * from software_cis where is_numeric(ci_class) = 0 You''ll have to adapt that for your specific database. I''m thinking you should have at least one row returned. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---