ruby-on-rails – 使用Rails 3的PostgreSQL JSON列类型

Rails 3中的以下迁移工作原理:
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

…但schema.rb现在报告不完整

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

所以rake db:reset将无法创建user_actions表.

解决方法

从: https://github.com/diogob/activerecord-postgres-hstore只需在application.rb中设置以下内容
config.active_record.schema_format = :sql

现在将使用structure.sql而不是schema.rb来使用rake db:reset或rake db:prepare从头创建数据库,并将特定于PostGres.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...