LoginSignup
0
0

More than 5 years have passed since last update.

DataMapper + PostgreSQL で Binary 型プロパティを使う

Posted at
class Hoge
  include DataMapper::Resource

  property :id, Serial
  property :binary, Binary
end

dm-migrations gem (v1.2.0) を使っていて、データベースが PostgreSQL の場合、上記のように Binary 型がのプロパティがある状態で DataMapper.auto_upgrade! などを実行すると下記のエラーが出る。

type modifier is not allowed for type "bytea" LINE 1: ... "binary" BYTEA(50), ...

PostgreSQL の BYTEA 型では長さを制限しないが、DataMapper の Binary プロパティは String プロパティから長さ制限 (= 50) を継承していて、制限を設定しようとするのが原因っぽい。

インストールされた dm-migrations gem のソースを直接編集できるなら、Removing limit from Binary column for PostgreSQL in datamapper - Stack Overflow のやり方で修正することもできる。

Heroku などでは、

# Gemfile
gem 'dm-migrations', github: 'titanous/dm-migrations', ref: 'a4de508'

で動いた。

修正の Pull Request (datamapper/dm-migrations#33) は v1.2.0 のリリース前にマージされてるけど、なぜか v1.2.0 には含まれてないっぽい。

v1.2 にその #33 を含める Pull Request (datamapper/dm-migrations#45) もあったけど、数ヶ月間無反応で、リクエストした人が close した様子。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0