Rails Migration: How to increase column data type size by using ROR migration

Ruby on-RailsRubyMigration

Ruby on-Rails Problem Overview


My users table login column is String type with limit of 40 characters. Now I am planning to increase the limit to 55 characters.

Any one please let me know how can we increase this limit by using ROR migration.

Thanks, Sravan

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

class YourMigration < ActiveRecord::Migration
  def up
    change_column :users, :login, :string, :limit => 55
  end

  def down
    change_column :users, :login, :string, :limit => 40
  end
end

Solution 2 - Ruby on-Rails

class YourMigration < ActiveRecord::Migration
  def change
    change_column :users, :login, :string, :limit => 55
  end
end

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSravan KumarView Question on Stackoverflow
Solution 1 - Ruby on-RailsbeesasohView Answer on Stackoverflow
Solution 2 - Ruby on-RailstirdadcView Answer on Stackoverflow