如何增加栏杆宝石中的栏位? [英] How can I increase a field in a rails gem?
问题描述
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
或者如果您想要更长时间$ 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屋!