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

kidbrax picture kidbrax · Aug 14, 2010 · Viewed 33.4k times · Source

Is the following correct?

 change_column :tablename, :fieldname, :limit => null

Answer

Jeremy Baker picture Jeremy Baker · Dec 7, 2010

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.