我收到此错误:
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)
因为" readable_type"只有20个字符,我传入" PublicActivity :: ORM :: ActiveRecord :: Activity"。
这与using gem unread with public_activity同样的问题(显然已经解决了问题,但没有说明如何(见他最初的更新))
答案 0 :(得分:1)
为什么不进行迁移并将readable_type
更改为更长的类型?像这样:
change_column :read_marks, :readable_type, "varchar(255)"
或者如果你想要更长时间:
change_column :read_marks, :readable_type, :text
由于您正在使用PostgreSQL,因此使用“无限”长度类型没有任何缺点,例如: :text
。
答案 1 :(得分:0)
从您添加的链接中
UPDATE
AH! It was the readable_type field having a limit of only 20 that was truncating my class name. Now it works after I increased the size.
在数据库上,将“readable_type”列的大小增加到大于20的大小