【问题标题】:Rails and jsonb type "jsonb" does not existRails 和 jsonb 类型“jsonb”不存在
【发布时间】:2015-06-06 06:19:34
【问题描述】:
psql --version
psql (PostgreSQL) 9.4.1

rails -v
Rails 4.2.0

我通过这样的迁移添加了一个 jsonb 列

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

我收到此错误:

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

有什么帮助吗?

【问题讨论】:

  • 我前几天也看到了这个问题,似乎没有任何解决方案。你能尝试升级到 4.2.1 还是降级你的 rails
  • @argentum47 我认为这是我的错,我会修复它并发布答案。谢谢。

标签: ruby-on-rails postgresql jsonb


【解决方案1】:

环顾四周,我通过运行正确的命令发现我的 postgresql 版本不是 9.4

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

所以我只需将我的 postgresql 升级到 9.4。

顺便说一句,我跟着this article 进行了升级,我觉得非常方便。

现在:

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

希望这对处于相同情况的人有所帮助。

【讨论】:

  • 正确。升级 postgresql 版本有帮助。这个other upgrading guide 也可以。
  • 该指南适用于大多数 debian 系统 - 但对于 Ubuntu 14.04(它没有 postgres-9.4 包/存储库)还有更多工作要做。对于旧版本的 Ubuntu,请在 askubuntu.com 上搜索,因为那里有大量的解决方案。
  • 对于遇到此问题的其他人,我使用 this article 并在 Ubuntu 14.04 上直接从 Postgres 9.3 成功升级到 10.5。该文章适用于 9.4 -> 9.5,但适用于 9.3 -> 10.5!
  • Here 是指导在 Ubuntu 14.04 上安装 postgres-9.4 的说明
猜你喜欢
  • 1970-01-01
  • 2015-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多