11

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

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

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

Thanks in advance!

Antonio682
  • 363
  • 1
  • 4
  • 18
  • 1
    MySQL 5.5... from the docs JSON native data type starts from 5.7 - [json](https://dev.mysql.com/doc/refman/5.7/en/json.html) – Mat Dec 24 '16 at 12:33
  • I was so blind I've already updated to MySQL 5.7 and it's working. – Antonio682 Dec 24 '16 at 12:46
  • Thanks for your help! – Antonio682 Dec 24 '16 at 12:47
  • I made my comment the answer – Mat Dec 24 '16 at 12:55
  • PostgreSQL is a great alternative to MySQL and offers more datatypes including JSON, JSONB and Hstore. These datatypes all supported by the PostgreSQL adapter. Here is some more information about it: http://edgeguides.rubyonrails.org/active_record_postgresql.html – farrows76 Dec 25 '16 at 03:19

1 Answers1

11

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

Mat
  • 2,156
  • 2
  • 16
  • 29