In a rails migration, how can you remove the limit of a field In a rails migration, how can you remove the limit of a field ruby ruby

In a rails migration, how can you remove the limit of a field


If you previously specified a limit in a migration and want to just remove the limit, you can just do this:

change_column :users, :column, :string, :limit => 255

255 is the standard length for a string column, and rails will just wipe out the limit that you previously specified.

Updated:

While this works in a number of Rails versions, you would probably be better suited to use nil like in Giuseppe's answer.

change_column :users, :column, :string, :limit => nil

That means the only thing you were doing wrong was using null instead of nil.


Here's what happened to me.

I realized that a string field I had in a table was not sufficient to hold its content, so I generated a migration that contained:

def self.up  change_column :articles, :author_list, :textend

After running the migration, however, the schema had:

create_table "articles", :force => true do |t|  t.string   "title"  t.text     "author_list", :limit => 255end

Which was not OK. So then I "redid" the migration as follows:

def self.up  # careful, it's "nil", not "null"  change_column :articles, :author_list, :text, :limit => nilend

This time, the limit was gone in schema.rb:

create_table "articles", :force => true do |t|  t.string   "title"  t.text     "author_list"end


Change the column type to :text. It does not have a limit.

change_column :tablename, :fieldname, :text, :limit => nil