简体   繁体   English

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

[英]Rails 4 JSON attribute type not working with Postgres

I forked a repo from someone I'm collaborating with, and I'm just trying to get my development environment up and running. 我与我合作的人分享了一个回购,我只是想让我的开发环境正常运行。 One of the migrations has a json attribute and we're using Postgres for both dev and production: 其中一个迁移有一个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

database.yml database.yml的

development:
  adapter: postgresql
  database: examgen_development
  host: localhost

When I run the rake db:migrate , I get an error that would lead me to believe that PG doesn't support JSON column types: 当我运行rake db:migrate ,我收到一个错误,导致我认为PG不支持JSON列类型:

PG::Error: ERROR:  type "json" does not exist

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

Interestingly, when I check the version of PG I'm using with 'psql' it shows 9.0.4. 有趣的是,当我检查我使用'psql'的PG版本时,它显示9.0.4。 Whereas when I use 'postgres' it shows 9.2.1. 而当我使用'postgres'时,它显示9.2.1。 So I'm not exactly sure what version I'm using and how to go about switching back and forth. 所以我不确定我正在使用什么版本以及如何来回切换。

psql --version
psql (PostgreSQL) 9.0.4

postgres --version
postgres (PostgreSQL) 9.2.1

Does anyone have thoughts as to why I'm getting that Postgres error? 有没有人想到为什么我得到Postgres错误?

OK, so it turns out at one point I had installed postgres via homebrew, and had also done so with Postgres.app at a different time. 好吧,事实证明我曾经通过自制软件安装了postgres,并且在不同的时间也使用了Postgres.app。 I began to realize this by checking the version of 'psql' and 'postgres' and noticed the distinction. 我通过检查'psql'和'postgres'的版本开始意识到这一点,并注意到了区别。

psql --version
psql (PostgreSQL) 9.0.4

postgres --version
postgres (PostgreSQL) 9.2.4

I uninstalled Postgres.app using their documentation here and then using homebrew ensured I was using the most recent version of postgres. 在这里使用他们的文档卸载了Postgres.app然后使用自制软件确保我使用的是最新版本的postgres。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM