PostgreSQL字符串(255)限制 - Rails,Ruby和Heroku

mar*_*ion 28 postgresql ruby-on-rails heroku ruby-on-rails-3

所以我有一个comments结构如下的表:

# == 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)
Run Code Online (Sandbox Code Playgroud)

这是我收到的错误消息:

ActiveRecord::StatementInvalid (PGError: ERROR:  value too long for type character varying(255)
Run Code Online (Sandbox Code Playgroud)

如何使用Rails 3.x和Heroku在PG列中存储长文本?

迁移将如何解决此问题?

谢谢.

Yul*_*ule 60

您需要使用文本而不是字符串.

迁移将有以下几点:

change_column :comments, :body, :text, :limit => nil
Run Code Online (Sandbox Code Playgroud)

  • 我要做的一个改变是,确保指定`:limit => nil`,否则将在Rails 3.x中的模式中添加一个255的`limit`. (6认同)
  • 不再需要`limit:nil`.使用rails 3.2.11,将type设置为:text将Postgres列类型设置为"text".没有隐含限制:255. (4认同)