即将迁移 :string 但我想 :text 可能会更好。性能/目的?
class CreateScrapes < ActiveRecord::Migration
def self.up
create_table :scrapes do |t|
t.text :saved_characters
t.text :sanitized_characters
t.string :href
t.timestamps
end
end
def self.down
drop_table :scrapes
end
end
我即将 rake db:migrate,并且正在考虑属性类型是否应该使用 text
或 string
。由于 saved_characters
和 sanitized_characters
将是具有数千个 unicode 值的数组,它基本上是逗号分隔的数据,我不确定 `:text' 是否真的是正确的方法这里。你会怎么办?
class CreateScrapes < ActiveRecord::Migration
def self.up
create_table :scrapes do |t|
t.text :saved_characters
t.text :sanitized_characters
t.string :href
t.timestamps
end
end
def self.down
drop_table :scrapes
end
end
I'm about to rake db:migrate and I'm think about the attribute type if I should be using text
or string
. Since saved_characters
and sanitized_characters
will be arrays with thousands of unicode values, its basically comma delimited data, I'm not sure if `:text' is really the right way to go here. What would you do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用 MySQL,
:string
和:text
之间的真正区别在于长度。 Rails 对:string
列使用varchar
列类型,并对:string
列设置 255 个字符的限制。:text
令人惊讶的是,使用了text
列。对我来说,这表明
:string
对于您的列来说是一个非常糟糕的选择,因为它们可能超过 255 个字符。Assuming you're on MySQL, the real difference between
:string
and:text
is length. Rails uses thevarchar
column type for:string
columns, and sets a 255 character limit on:string
columns.:text
, usuprisingly, uses thetext
column.To me, this suggests that
:string
would be a really bad choice for your columns, as they are likely to exceed 255 characters.:string 只有 255 个字符。你可能想要 :text 因为你提到了数千。
:string is only 255 characters. you probably want :text since you mention thousands.