Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is the following correct?

 change_column :tablename, :fieldname, :limit => null 
like image 824
kidbrax Avatar asked Aug 14 '10 16:08

kidbrax


People also ask

Can you edit a migration file Rails?

If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run rake db:migrate.

How does migration work in Rails?

A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.


1 Answers

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.

like image 176
Jeremy Baker Avatar answered Sep 29 '22 19:09

Jeremy Baker