如何通过Rails 5迁移在MySQL中添加JSON列 [英] How to add a JSON column in MySQL with Rails 5 Migration

查看:92
本文介绍了如何通过Rails 5迁移在MySQL中添加JSON列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过运行以下命令在MySQL数据库中添加json列:

I'm trying to add a json column in MySQL db by running:

class AddStatisticsToPlayerStatistic < ActiveRecord::Migration[5.0]
    def change
       add_column :player_statistics, :statistics, :json
    end
end

但是当我尝试运行rake db:migrate时出现此错误

But I'm getting this error when I try to run 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列.正确吗?

Does anyone know how to add a JSON column in MySQL Ver 14.14 Distrib 5.5.53. properly?

提前谢谢!

推荐答案

MySQL文档说JSON本机数据类型从5.7.8开始-

MySQL docs says that JSON native data type starts from 5.7.8 - json

这篇关于如何通过Rails 5迁移在MySQL中添加JSON列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆