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' 是否真的是正确的方法这里。你会怎么办?
最佳答案
假设您使用的是 MySQL,:string
和 :text
之间的真正区别在于长度。 Rails 对 :string
列使用 varchar
列类型,并为 :string
列设置 255 个字符的限制。 :text
令人惊讶的是,使用了 text
列。
对我来说,这表明 :string
对于您的列来说是一个非常糟糕的选择,因为它们可能超过 255 个字符。
关于sql - 即将迁移 :string but I'm thinking :text might be better. 性能/目的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4632177/