如何使用Rails 5 Migration在MySQL中添加JSON列

时间:2016-12-24 12:14:53

标签: mysql ruby-on-rails ruby-on-rails-5 c9.io

我试图通过运行:

在MySQL数据库中添加一个json列
class AddStatisticsToPlayerStatistic < ActiveRecord::Migration[5.0]
    def change
       add_column :player_statistics, :statistics, :json
    end
end

但是当我尝试运行rake db:migrate

时,我收到此错误
Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'json' at line 1: ALTER TABLE `player_statistics` ADD `statistics` json

有没有人知道如何在MySQL Ver 14.14 Distrib 5.5.53中添加JSON列。正常?

提前致谢!

1 个答案:

答案 0 :(得分:5)

MySQL文档说JSON原生数据类型从5.7.8开始 - json