【发布时间】:2017-05-09 20:25:54
【问题描述】:
我正在尝试通过运行在 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 列。正常吗?
提前致谢!
【问题讨论】:
-
MySQL 5.5... 来自文档 JSON 本机数据类型从 5.7 开始 - json
-
我太盲目了,我已经更新到 MySQL 5.7 并且它正在工作。
-
感谢您的帮助!
-
我的评论是答案
-
PostgreSQL 是 MySQL 的绝佳替代品,并提供更多数据类型,包括 JSON、JSONB 和 Hstore。 PostgreSQL 适配器都支持这些数据类型。以下是有关它的更多信息:edgeguides.rubyonrails.org/active_record_postgresql.html
标签: mysql ruby-on-rails ruby-on-rails-5 c9.io