Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 886
Sravan Kumar Avatar asked Mar 12 '14 12:03

Sravan Kumar


People also ask

What is migration in ROR?

Migrations are a convenient way to alter your database schema over time in a consistent way. They use a Ruby DSL so that you don't have to write SQL by hand, allowing your schema and changes to be database independent. You can think of each migration as being a new 'version' of the database.

What is add_index in rails migration?

add_index(table_name, column_name, options = {}) public. Adds a new index to the table. column_name can be a single Symbol, or an Array of Symbols. The index will be named after the table and the column name(s), unless you pass :name as an option.


2 Answers

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 
like image 87
beesasoh Avatar answered Sep 27 '22 23:09

beesasoh


class YourMigration < ActiveRecord::Migration   def change     change_column :users, :login, :string, :limit => 55   end end 
like image 26
tirdadc Avatar answered Sep 27 '22 21:09

tirdadc