Search code examples
ruby-on-railssqliterails-migrationsruby-on-rails-5

How can I change column type on rails 5


I insert a column in my sqlite with a wrong type "stringimage".

enter image description here

How can I change the column type to string?

I tried change_column :users, :uid, :string

and

def up
  change_table :users do |t|
    t.change :uid, :stringimage
  end
end
def down
  change_table :users do |t|
    t.change :uid, :string
  end
end

but it doesn't works. I tried many things but none of it works, maybe because I'm using rails 5.


Solution

  • You Need to write following two definitions into your migration :

    def up
      change_column :my_table, :my_column, :string
    end
    
    def down
      change_column :my_table, :my_column, :stringimage
    end