【问题标题】:Use PostgreSQL JSON column type with Rails 3在 Rails 3 中使用 PostgreSQL JSON 列类型
【发布时间】:2013-12-19 03:03:25
【问题描述】:

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 表。

【问题讨论】:

    标签: ruby-on-rails json postgresql activerecord


    【解决方案1】:

    来自:https://github.com/diogob/activerecord-postgres-hstore 只需在 application.rb 中设置以下内容:

    config.active_record.schema_format = :sql
    

    现在将使用 structure.sql 代替 schema.rb 来使用 rake db:resetrake db:prepare 从头开始​​创建数据库,并将特定于 PostGres。

    【讨论】:

    • 不错!我什至不知道这是可能的。
    猜你喜欢
    • 2014-07-15
    • 2016-05-31
    • 2015-09-28
    • 2014-10-07
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多