2
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 并且我正在考虑是否应该使用属性类型textor string。由于saved_characters并且sanitized_characters将是具有数千个 unicode 值的数组,它基本上是逗号分隔的数据,我不确定 `:text' 是否真的是正确的方法。你会怎么做?

4

2 回答 2

4

:string假设您使用的是 MySQL,和之间的真正区别在于:text长度。Rails 对列使用varchar列类型:string,并为列设置 255 个字符的限制:string:text,令人惊讶的是,使用该text列。

对我来说,这表明这:string对于您的列来说是一个非常糟糕的选择,因为它们可能超过 255 个字符。

于 2011-01-08T03:48:00.920 回答
2

:string 只有 255 个字符。您可能想要 :text ,因为您提到了数千个。

于 2011-01-08T03:47:17.107 回答