About to migrate :string but I'm thinking :text might be better. Performance/Purpose?
Question
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?
Solution
Assuming you're on MySQL, the real difference between :string
and :text
is length. Rails uses the varchar
column type for :string
columns, and sets a 255 character limit on :string
columns. :text
, usuprisingly, uses the text
column.
To me, this suggests that :string
would be a really bad choice for your columns, as they are likely to exceed 255 characters.
OTHER TIPS
:string is only 255 characters. you probably want :text since you mention thousands.