med*_*zid 34 postgresql ruby-on-rails jsonb
psql --version
psql (PostgreSQL) 9.4.1
rails -v
Rails 4.2.0
Run Code Online (Sandbox Code Playgroud)
我通过迁移添加了一个jsonb列
class AddPreferencesToUsers < ActiveRecord::Migration
def change
add_column :users, :preferences, :jsonb, null: false, default: '{}'
add_index :users, :preferences, using: :gin
end
end
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
PG::UndefinedObject: ERROR: type "jsonb" does not exist
LINE 1: SELECT 'jsonb'::regtype::oid
Run Code Online (Sandbox Code Playgroud)
任何帮助?
med*_*zid 66
环顾四周后,我通过运行正确的命令发现我的postgresql版本不是9.4
postgres=# SHOW SERVER_VERSION;
server_version
----------------
9.1
Run Code Online (Sandbox Code Playgroud)
所以我只是将postgresql升级到9.4.
顺便说一句,我按照这篇文章进行升级,我觉得非常方便.
现在:
postgres=# SHOW SERVER_VERSION;
server_version
----------------
9.4.1
Run Code Online (Sandbox Code Playgroud)
希望这能帮助处于同样情况的人.