问题
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))
回答1:
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
.
回答2:
From the link you added:
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.
On the database, increase the size of the column "readable_type" to a bigger size than 20
来源:https://stackoverflow.com/questions/15194261/how-can-i-increase-a-field-in-a-rails-gem