In rail migration, how can you remove the field limit

Is it correct?

change_column :tablename, :fieldname, :limit => null 
+44
ruby ruby-on-rails rails-migrations
Aug 14 '10 at 16:51
source share
6 answers

If you previously specified a restriction on the transfer and want to simply remove the limit, you can simply do this:

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

255 is the standard length of the row column, and the rails simply destroy the limit you previously specified.

Updated:

While this works on many versions of Rails, you are probably better suited to using nil , as in Giuseppe's answer.

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

This means that the only thing you did wrong is to use null instead of nil .

+88
Dec 07 2018-10-12T00:
source share
β€” -

This is what happened to me.

I realized that the string field that I had in the table is not enough to store its contents, so I created a migration containing:

 def self.up change_column :articles, :author_list, :text end 

However, after the migration, the scheme had:

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

That was not OK . So, I redid the migration as follows:

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

This time the limit ended in schema.rb:

 create_table "articles", :force => true do |t| t.string "title" t.text "author_list" end 
+34
Dec 29 '10 at 2:08 a.m.
source share

Change the column type to :text . He has no limit.

 change_column :tablename, :fieldname, :text, :limit => nil 
+3
Dec 07 2018-10-12T00:
source share

Rows without limits are not something that most databases support: you must specify the size in the varchar(SIZE) definition varchar(SIZE) .
Although you could try, I would personally go with :limit => BIG_ENOUGH_NUMBER . You can also use the CLOB type for very large texts.

0
Aug 14 '10 at 17:01
source share

To make it independent of the db driver, you need to write smth as follows:

 add_column :tablename, :fieldname_tmp, :text Tablename.reset_column_information Tablename.update_all("fieldname_tmp = fieldname") remove_column :tablename, :fieldname rename_column :tablename, :fieldname_tmp, :fieldname 
0
Aug 14 '10 at 21:18
source share

Today I was the same boat, trying to remove the limit added to the text box, and it won’t take. I tried several migrations.

Rails 4.2.7.1 Ruby 2.3.1p112

In the end, the only thing that worked was an indication of the limit of 255. Trying to adapt to everything else would not work for me.

0
Mar 31 '17 at 16:24
source share



All Articles