Rails with mysql cannot create json type column

I have created Rails(3.2) application with mysql(5.7.16) backend. I can't add json type column when creating table but I can able to add json column by new migration. I have used following code in create table migration, What was wrong here ?

class CreateShoppingCartItemSpecialInfos < ActiveRecord::Migration
  def change
    create_table :shopping_cart_item_special_infos do |t|
      t.integer :shopping_cart_checkout_option_id
      t.json :special_info

      t.timestamps
    end
  end
end

Upvotes: 2

Views: 1557

Answers (1)

Blackcoat77
Blackcoat77

Reputation: 1625

You should be able to create JSON column type. Probably you run in couple of errors. In case there is a error after migration try first reverting it:

rake db:migrate:down VERSION=<version>

Than you can try like this:

class CreateShoppingCartItemSpecialInfos < ActiveRecord::Migration
  def change
    create_table :shopping_cart_item_special_infos do |t|
      t.integer :shopping_cart_checkout_option_id
      t.column :special_info, :json

      t.timestamps
    end
  end
end

Upvotes: 3

Related Questions