Rails and jsonb type “jsonb” does not exist

前提是你 提交于 2019-12-21 03:09:13

问题


psql --version
psql (PostgreSQL) 9.4.1

rails -v
Rails 4.2.0

I added a jsonb column through migration like that

class AddPreferencesToUsers < ActiveRecord::Migration
  def change
    add_column :users, :preferences, :jsonb, null: false, default: '{}'
    add_index :users, :preferences, using: :gin
  end
end

I get this error :

PG::UndefinedObject: ERROR:  type "jsonb" does not exist
LINE 1: SELECT 'jsonb'::regtype::oid

any help ?


回答1:


After looking around I discovered that my postgresql version is not 9.4 by running the right command

postgres=# SHOW SERVER_VERSION;
server_version 
----------------
9.1

So I had simply to upgrade my postgresql to 9.4.

By the way I followed this article to do the upgrading which I found very handy.

Now :

postgres=# SHOW SERVER_VERSION;
 server_version 
----------------
 9.4.1

Hope this help someone in the same situation.



来源:https://stackoverflow.com/questions/29393562/rails-and-jsonb-type-jsonb-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!