Rails 4 - PostgreSQL 9.4 中的 jsonb 不存在。

8

我在我的项目中使用了Rails 4和PostgreSQL 9.4。当我运行"rdd && rdc && rdm && rds"时,出现了错误PG::UndefinedObject: ERROR: type "jsonb" does not exist

怎样才能解决这个错误?请告诉我。

我的迁移文件:

class CreateConsultingLocationDoctorSchedules < ActiveRecord::Migration
   def change
      create_table :consulting_location_doctor_schedules do |t|
           t.belongs_to :consulting_location_doctor
           t.datetime :schedule_date, null: false
           t.jsonb :slot_details, index: true, default: {}
           t.daterange :start_and_end_time, null: false
           t.datetime :deleted_at
           t.belongs_to :deleted_by

           t.timestamps
      end
   end
end

感谢您的帮助!


2
这意味着你的Rails版本实际上不是4.2,因为至少你的格式是正确的,必需的版本是Rails 4.2和PostgreSQL 9.4。你能仔细检查一下吗? - Roope Hakulinen
我有同样的问题,我正在使用Rails 4.2和pg 9.4.1,你找到任何解决方案了吗? - medBouzid
2
重复的问题和解决方案在这里:https://dev59.com/wl0b5IYBdhLWcg3wQPbw - deivid
1个回答

7

请检查您在开发中连接的是否是正确的Postgres实例。

rails console
ActiveRecord::Base.connection.execute("select version();").first["version"]

如果您确信正在运行9.4版本,则可能是您有两个Postgres服务器在运行。一个是9.4,另一个是旧的。
我也遇到了这个问题,我编辑了我的database.yml并指定了host:'localhost'

在我的情况下,正确的Postgres运行在5433端口。 - Greg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接