Use PostgreSQL JSON column type with Rails 3

The following migration in Rails 3 works:

class CreateUserActions < ActiveRecord::Migration def up create_table :user_actions do |t| t.datetime :time t.integer :user_id t.text :action t.column :details, :json t.timestamps end end def down drop_table 'user_actions' end end 

... but schema.rb now incomplete reporting

 # Could not dump table "user_actions" because of following StandardError # Unknown type 'json' for column 'details' 

So rake db:reset will not be able to create the user_actions table.

+7
json ruby-on-rails activerecord postgresql
source share
1 answer

From: https://github.com/diogob/activerecord-postgres-hstore just set the following in application.rb:

 config.active_record.schema_format = :sql 

Now, struct.sql will be used instead of schema.rb to create the database from scratch using rake db:reset or rake db:prepare and will be PostGres specific.

+8
source share

All Articles