简体   繁体   English

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

[英]PostgreSQL string(255) limit - Rails, Ruby and Heroku

So I have a comments table that is structured like this: 所以我有一个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)

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? 如何使用Rails 3.x和Heroku在PG列中存储长文本?

What would the migration look like to fix this issue? 迁移将如何解决此问题?

Thanks. 谢谢。

You would need to use text instead of string. 您需要使用文本而不是字符串。

Migration would be something along the lines of: 迁移将有以下几点:

change_column :comments, :body, :text, :limit => nil

All the time I solve this problem by this type of query 我一直通过这种类型的查询来解决这个问题
ALTER TABLE your_table_name ALTER COLUMN your_column_name TYPE text;


Character varying has limited length and you can not pass this length. 变化的字符长度有限,你不能通过这个长度。
text is a variable which has no limit. text是一个没有限制的变量。
So you can convert your column type from character varying(which has a length) to 因此,您可以将列类型从字符变化(具有长度)转换为
text (which has no limit). 文字(没有限制)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM