Rails - How to add a BLOB column using ActiveRecord?
14,454
The migration seems to be correct except the down part. It should be:
class AddVersionCommentToMetaData < ActiveRecord::Migration
def self.up
add_column :meta_data, :version_comment, :binary, :limit => 10.megabyte
end
def self.down
remove_column :meta_data, :version_comment
end
end
double check for typos. And what version of rails are you using? It works well in rails 3.0.7.
Related videos on Youtube
Author by
Amokrane Chentir
Updated on June 04, 2022Comments
-
Amokrane Chentir almost 2 years
I need to create a BLOB column to store some text content.
I have read somewhere that I need to do the following:
class AddVersionCommentToMetaData < ActiveRecord::Migration def self.up add_column :meta_data, :version_comment, :binary, :limit => 10.megabyte end def self.down remove_column :meta_data, :version_comment end end
However, it gives the following error message:
PGError: ERROR: type modifier is not allowed for type "bytea" LINE 1: ..."meta_data" ADD COLUMN "version_comment_extended" bytea(1048... ^ : ALTER TABLE "meta_data" ADD COLUMN "version_comment_extended" bytea(10485760)
Any idea?
Please note that I am using PostgreSQL. Thanks!
-
Amokrane Chentir over 12 yearsActually I made the typo when copy pasting on StackOverflow (the real column name is version_comment_extended but I made it shorter on purpose to improve the readability. I am using Rails 3.0.5.