Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I have a comments table that is structured like this:

# == Schema Information
#
# Table name: comments
#
#  id         :integer         not null, primary key
#  body       :string(255)
#  notified   :boolean
#  user_id    :integer
#  stage_id   :integer
#  created_at :datetime
#  updated_at :datetime
#  client_id  :integer
#  author     :string(255)

This is the error message I am getting:

ActiveRecord::StatementInvalid (PGError: ERROR:  value too long for type character varying(255)

How do I store long text in a PG column using Rails 3.x and Heroku?

What would the migration look like to fix this issue?

Thanks.

share|improve this question
1  
Are you looking for anything more than: stackoverflow.com/questions/4103141/… ? –  John Plummer Mar 20 '12 at 10:20
    
No...that's exactly what I was looking for. Thanks! –  marcamillion Mar 20 '12 at 11:17
add comment

1 Answer

up vote 45 down vote accepted

You would need to use text instead of string.

Migration would be something along the lines of:

change_column :comments, :body, :text, :limit => nil
share|improve this answer
6  
One change to that I would make is, make sure to specify :limit => nil, otherwise a limit of 255 will be added to the schema in Rails 3.x. –  marcamillion Mar 20 '12 at 11:19
3  
The limit:nil is no longer necessary. Using rails 3.2.11, setting type to :text sets the Postgres column type to 'text'. There is no implicit limit:255. –  Noach Magedman Feb 5 '13 at 9:30
    
Rails 3.2.8 , :limit => nil is needed. –  Keen Learner Mar 26 '13 at 16:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.