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.