I have followed all suggestions from similar questions but none has solved my problem.
I want to change the field gl_code from string to integer and have tried the following:
class ChangeCategoryGlCode < ActiveRecord::Migration
def change
# Category.all.each { |cat| cat.update(gl_code: cat.gl_code.to_i) }
Category.where("gl_code IS NULL OR gl_code = ''").update_all({gl_code: '0'})
# change_column :categories, :gl_code, :integer, using: 'gl_code::integer'
change_column :categories, :gl_code, 'integer USING CAST(gl_code AS integer)'
end
end
But nothing seems to work. I even ssh'd to the server and run the commands manually but whenever I try to deploy it fails at rake db:migrate with the error above.
Any suggestions/hints are welcome.
Edit: If that matters, I am using the Apartment gem, and have tried changing the gl_code for Category for each tenant.
aaain yourgl_codecolumn cannot be converted to an integer. What's unclear about that?gl_code'aaa' lying around anywhere?gl_code"aaa" but there is no item with a code like that.Category.where(gl_code: "aaa")returns an empty list. I also triedCategory.all.each { |c| puts c.gl_code if c.gl_code.kind_of?(String) }and I still get nothing. Tbh I remember adding a gl_code like that (for testing purposes) but shouldn't what I tried return something?Category.all.each { |cat| cat.update(gl_code: cat.gl_code.to_i) }or ` Category.where("gl_code IS NULL OR gl_code = ''").update_all({gl_code: '0'}). Those should have fixed anygl_code` that is a string, or am I missing something?