Ruby-on-rails Rails 和 jsonb 类型“jsonb”不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29393562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails and jsonb type "jsonb" does not exist
提问by medBouzid
psql --version
psql (PostgreSQL) 9.4.1
rails -v
Rails 4.2.0
I added a jsonb column through migration like that
我通过这样的迁移添加了一个 jsonb 列
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 ?
有什么帮助吗?
回答by medBouzid
After looking around I discovered that my postgresql version is not 9.4 by running the right command
环顾四周后,我通过运行正确的命令发现我的 postgresql 版本不是 9.4
postgres=# SHOW SERVER_VERSION;
server_version
----------------
9.1
So I had simply to upgrade my postgresql to 9.4.
所以我只需要将我的 postgresql 升级到 9.4。
By the way I followed this articleto 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.
希望这可以帮助处于相同情况的人。

