I’m trying to create a model with a Binary field in Datamapper for Rails 3 that looks like so:
class Image
include DataMapper::Resource
# attributes
property :id, Serial
property :url, String
property :file_name, String
property :content_type, String
property :data, Binary
property :created_at, DateTime
property :updated_at, DateTime
end
However, when I try to migrate I get the following:
ERROR: type modifier is not allowed for type "bytea"
LINE 1: ..." VARCHAR(50), "content_type" VARCHAR(50), "data" BYTEA(50),...
I can’t seem to find a way to remove the limit of 50 that datamapper is placing upon the field. Anybody know how to do this or fix the problem?
This is a bug in DataMapper. Check out this thread. It has already been fixed in GitHub, but it hasn’t made it to a release yet. If you’re ok with it, it’s very easy to patch dm-migrations to fix it. In “dm-migrations/adapters/dm-do-adapter.rb”, you find the line that says
and append
to the end of it.
I tested your code here and it works with the patch applied.