PostgreSQL string(255) 限制 - Rails、Ruby 和 Heroku
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9784622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL string(255) limit - Rails, Ruby and Heroku
提问by marcamillion
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.
谢谢。
回答by Yule
You would need to use text instead of string.
您需要使用文本而不是字符串。
Migration would be something along the lines of:
迁移将遵循以下原则:
change_column :comments, :body, :text, :limit => nil
回答by Harun ERGUL
All the time I solve this problem by this type of query ALTER TABLE your_table_name ALTER COLUMN your_column_name TYPE text;
我一直通过这种类型的查询来解决这个问题 ALTER TABLE your_table_name ALTER COLUMN your_column_name TYPE text;
Character varyinghas limited length and you can not pass this length.
textis a variable which has no limit.
So you can convert your column type from character varying(which has a length) to
text (which has no limit).
字符变化的长度是有限的,你不能传递这个长度。
text是一个没有限制的变量。
因此,您可以将列类型从字符变化(具有长度)转换为
文本(没有限制)。