rails中的字符串和文本之间的区别? [英] Difference between string and text in rails?
本文介绍了rails中的字符串和文本之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Rails 制作一个新的网络应用程序,我想知道 string
和 text
之间有什么区别?什么时候应该使用?
I'm making a new web app using Rails, and was wondering, what's the difference between string
and text
? And when should each be used?
推荐答案
区别在于符号在查询语言中如何转换为其各自的列类型.
The difference relies in how the symbol is converted into its respective column type in query language.
使用 MySQL :string 映射到 VARCHAR(255)
with MySQL :string is mapped to VARCHAR(255)
:string | VARCHAR | :limit => 1 to 255 (default = 255)
:text | TINYTEXT, TEXT, MEDIUMTEXT, or LONGTEXT2 | :limit => 1 to 4294967296 (default = 65536)
参考:
应该什么时候使用?
作为一般经验法则,使用 :string
输入短文本(用户名、电子邮件、密码、标题等),使用 :text
输入更长的文本输入如描述、评论内容等
As a general rule of thumb, use :string
for short text input (username, email, password, titles, etc.) and use :text
for longer expected input such as descriptions, comment content, etc.
这篇关于rails中的字符串和文本之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文