9

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!

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.