Rails 3 Migration with longtext

dennismonsewicz picture dennismonsewicz · Dec 14, 2010 · Viewed 33.4k times · Source

I am needing to change a column type from text to longtext in my Rails script, but can't find anything on how to do this.

Has anyone ran across this?

Thanks! Dennis

Answer

Chuck Callebs picture Chuck Callebs · Dec 14, 2010

The text type handles tinytext, text, mediumtext, and longtext for MySQL, if that's what you're using. Just specify the upper bound using :limit => ...

Example:

change_column :articles, :body, :text, :limit => 4294967295

The default value of limit is 65535, as expected.

1 to 255 bytes: TINYTEXT
256 to 65535 bytes: TEXT
65536 to 16777215 bytes: MEDIUMTEXT
16777216 to 4294967295 bytes: LONGTEXT

The MySQL documentation can be found here.