ruby-on-rails – 使用Rails 3的PostgreSQL JSON列类型
发布时间:2020-12-16 19:09:06 所属栏目:百科 来源:网络整理
导读: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 'use
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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |