我用mysql(5.7.16)后端创建了Rails(3.2)应用程序。我在创建表时无法添加json类型列,但我可以通过新迁移添加json列。我在create table migration中使用了以下代码,这里有什么问题?
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
答案 0 :(得分:1)
您应该能够创建JSON列类型。可能你遇到了几个错误。如果迁移后出现错误,请先尝试恢复它:
rake db:migrate:down VERSION=<version>
你可以尝试这样:
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