Rails 4 JSON属性类型不适用于Postgres

dou*_*ets 6 postgresql json ruby-on-rails

我与我合作的人分享了一个回购,我只是想让我的开发环境正常运行.其中一个迁移有一个json属性,我们正在使用Postgres进行开发和生产:

class CreateExams < ActiveRecord::Migration
  def change
    create_table :exams do |t|
      t.belongs_to :user
      t.json :exam
      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

database.yml的

development:
  adapter: postgresql
  database: examgen_development
  host: localhost
Run Code Online (Sandbox Code Playgroud)

当我运行时rake db:migrate,我收到一个错误,导致我认为PG不支持JSON列类型:

PG::Error: ERROR:  type "json" does not exist
Run Code Online (Sandbox Code Playgroud)

但我知道Postgres 9.2支持JSON(即http://www.postgresql.org/docs/devel/static/datatype-json.html).

有趣的是,当我检查我使用'psql'的PG版本时,它显示9.0.4.而当我使用'postgres'时,它显示9.2.1.所以我不确定我正在使用什么版本以及如何来回切换.

psql --version
psql (PostgreSQL) 9.0.4

postgres --version
postgres (PostgreSQL) 9.2.1
Run Code Online (Sandbox Code Playgroud)

有没有人想到为什么我得到Postgres错误?

dou*_*ets 7

好吧,事实证明我曾经通过自制软件安装了postgres,并且在不同的时间也使用了Postgres.app.我通过检查'psql'和'postgres'的版本开始意识到这一点,并注意到了区别.

psql --version
psql (PostgreSQL) 9.0.4

postgres --version
postgres (PostgreSQL) 9.2.4
Run Code Online (Sandbox Code Playgroud)

在这里使用他们的文档卸载了Postgres.app ,然后使用自制软件确保我使用的是最新版本的postgres.