PostgreSQL字符串(255)限制 - Rails,Ruby和Heroku [英] PostgreSQL string(255) limit - Rails, Ruby and Heroku

查看:108
本文介绍了PostgreSQL字符串(255)限制 - Rails,Ruby和Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个注释表,它的结构如下所示:

 #==模式信息

#表名:注释

#id:integer不为null,主键
#body:string(255)
#通知:布尔
#user_id:整数
#stage_id:整数
#created_at:datetime
#updated_at:datetime
#client_id:integer
$ author:string(255)

这是我收到的错误消息:

  ActiveRecord :: StatementInvalid(PGError:ERROR:值类型字符变化太长(255)


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



什么将迁移看起来像解决这个问题?



谢谢。

解决方案

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



迁移将会是沿着以下路线:

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


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.

解决方案

You would need to use text instead of string.

Migration would be something along the lines of:

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

这篇关于PostgreSQL字符串(255)限制 - Rails,Ruby和Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆