如何增加栏杆宝石中的栏位? [英] How can I increase a field in a rails gem?

查看:102
本文介绍了如何增加栏杆宝石中的栏位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SQL(31.1ms)INSERT INTOread_marks(readable_id, ($ 1,$ 2,$ 3,$ 4)RETURNINGid[[readable_id,nil],[readable_type,PublicActivity :: ORM :: ActiveRecord :: Activity ],[timestamp,Mon,2013年3月4日03:29:52 UTC +00:00],[user_id,2]] 
PG ::错误:错误:值类型字符太长(20)

因为readable_type只能包含20个字符,所以我传入PublicActivity :: ORM :: ActiveRecord的::活动。

这与使用gem unread with public_activity (他明显解决了问题,但没有说明如何(请参阅他的底部UPDATE))

为什么不进行迁移并将 readable_type 更改为更长的类型?像这样:

  change_column:read_marks,:readable_type,varchar(255)


 <$ c  


或者如果您想要更长时间$ c> change_column:read_marks,:readable_type,:text

由于您使用的是PostgreSQL,使用无限长度类型的缺点,例如:text


I'm getting this error:

 SQL (31.1ms)  INSERT INTO "read_marks" ("readable_id", "readable_type", "timestamp", "user_id") VALUES ($1, $2, $3, $4) RETURNING "id"  [["readable_id", nil], ["readable_type", "PublicActivity::ORM::ActiveRecord::Activity"], ["timestamp", Mon, 04 Mar 2013 03:29:52 UTC +00:00], ["user_id", 2]]
PG::Error: ERROR:  value too long for type character varying(20)

Because "readable_type" only holds 20 characters, and I'm passing in "PublicActivity::ORM::ActiveRecord::Activity".

This is the same problem as using gem unread with public_activity (who apparently solved the problem but didn't say how (see his bottom UPDATE))

解决方案

Why not make a migration and change readable_type to a longer type? Something like this:

change_column :read_marks, :readable_type, "varchar(255)"

or if you want to go even longer:

change_column :read_marks, :readable_type, :text

Since you're using PostgreSQL, there's no disadvantage to using an "unlimited" length type, e.g. :text.

这篇关于如何增加栏杆宝石中的栏位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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