Rails 3: migration error when using json as a column type in an ActiveRecord backed by Postgres

前端 未结 3 2021
别跟我提以往
别跟我提以往 2020-12-28 15:39

I am running Rails 3.2.17 and Postgres 9.3.4. I created a new ActiveRecord model using \"rails generate\" and one of the column types is json. My intention is to use the jso

3条回答
  •  没有蜡笔的小新
    2020-12-28 16:15

    Change your migration like

    class CreateThing < ActiveRecord::Migration
      def change
        create_table :things do |t|
          t.integer :user_id
          t.column :json_data, :json   # Edited
          t.timestamps
        end
        add_index :things, :user_id
      end
    end
    

    And by default rake db tasks will look into schema.rb( which wont be the case for postgres) so in application.rb change it to

    config.active_record.schema_format = :sql
    

提交回复
热议问题