Search code examples
ruby-on-railsrubyrails-migrations

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


Is the following correct?

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

Solution

  • 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.