Ruby-on-rails 使用长文本进行 Rails 3 迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4443477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:53:30  来源:igfitidea点击:

Rails 3 Migration with longtext

ruby-on-railsmigrationruby-on-rails-3

提问by dennismonsewicz

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.

我需要在 Rails 脚本中将列类型从文本更改为长文本,但找不到有关如何执行此操作的任何信息。

Has anyone ran across this?

有没有人遇到过这个?

Thanks! Dennis

谢谢!丹尼斯

回答by Chuck Callebs

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

text型手柄tinytexttextmediumtext,和longtextMySQL的,如果这就是你使用的是什么。只需使用指定上限:limit => ...

Example:

例子:

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

The default value of limitis 65535, as expected.

limit正如预期的那样,默认值为65535。

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.

MySQL 文档可以在这里找到。