Rails 4 JSON attribute type not working with Postgres

I was looking for a repo from someone I collaborate with, and I'm just trying to start my development environment. One of the migrations has a json attribute, and we use Postgres for dev and production:

 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

 development: adapter: postgresql database: examgen_development host: localhost 

When I run rake db:migrate , I get an error message that would make me believe PG does not support JSON column types:

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

But I know that Postgres 9.2 supports JSON (i.e. http://www.postgresql.org/docs/devel/static/datatype-json.html ).

Interestingly, when I check the version of PG that I use with "psql", it shows 9.0.4. If I use "postgres", it shows 9.2.1. So I'm not quite sure which version I'm using and how to switch back and forth.

 psql --version psql (PostgreSQL) 9.0.4 postgres --version postgres (PostgreSQL) 9.2.1 

Does anyone have any thoughts on why I am getting this Postgres error?

+6
source share
1 answer

OK, so at some point I installed postgres via homebrew and also did this with Postgres.app at another time. I began to understand this by checking the version of "psql" and "postgres" and noticing the difference.

 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, I used the latest version of postgres.

+7
source

Source: https://habr.com/ru/post/950395/


All Articles