【问题标题】:How to add a JSON column in MySQL with Rails 5 Migration如何使用 Rails 5 迁移在 MySQL 中添加 JSON 列
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 当我升级我的 MySQL 服务器时,这个 sintaxis 工作得很好。
猜你喜欢
  • 2017-02-17
  • 2020-05-21
  • 2011-10-09
  • 2014-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多