PG::StringDataRightTruncation: 错误:PostgreSQL 字符串(255)限制 |赫鲁库 [英] PG::StringDataRightTruncation: ERROR: PostgreSQL string(255) limit | Heroku

查看:30
本文介绍了PG::StringDataRightTruncation: 错误:PostgreSQL 字符串(255)限制 |赫鲁库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Listings 控制器,用户可以添加描述.如果描述很长(应该很长),我会在 Heroku 中收到此错误:

I Have a Listings controller and users can add a description. If the description is long, which it should be, I receive this error in Heroku:

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

我该如何解决这个问题?

How can I fix this?

编辑

我发现(约翰也说过)我必须将我的表字符串(有限制)更改为 :text ,这是无限的.但是只在迁移中更改表似乎不起作用.

I found out (John said it also) that i have to change in my table string(which has a limit) to :text which is limitless. But only changing the table in the migration didn't seem to work.

我的已编辑列表迁移

class CreateListings < ActiveRecord::Migration
def change
create_table :listings do |t|
  t.string :title
  t.text :description, :limit => nil

  t.timestamps
end
end
end

但我仍然遇到 Heroku 问题 ->

But i'm still getting Heroku trouble ->

    2013-07-29T09:39:05.069692+00:00 app[web.1]: ActiveRecord::StatementInvalid (PG::StringDataRightTruncation: ERROR:  value too long for type character v rying(255)
2013-07-29T09:39:05.069870+00:00 app[web.1]:
2013-07-29T09:39:05.069692+00:00 app[web.1]: : INSERT INTO "listings" ("created_at", "description", "image_content_type", "image_file_name", "image_fil _size", "image_updated_at", "price", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"):
2013-07-29T09:39:05.069870+00:00 app[web.1]:   app/controllers/listings_controller.rb:35:in `block in create'
2013-07-29T09:39:05.069870+00:00 app[web.1]:   app/controllers/listings_controller.rb:34:in `create'
2013-07-29T09:39:05.069870+00:00 app[web.1]:
2013-07-29T09:39:05.069860+00:00 heroku[router]: at=info method=POST path=/listings host=vaultx.herokuapp.com fwd="178.59.173.169" dyno=web.1 connect=3 s service=1882ms status=500 bytes=1266

推荐答案

将列指定为 :text 类型而不是 :string 似乎可以解决这个问题.

It would seem that specifying the column as a :text type and not a :string would fix this problem.

这篇关于PG::StringDataRightTruncation: 错误:PostgreSQL 字符串(255)限制 |赫鲁库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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