rails4でDBにjsonのカラムを追加しようと考えています。しかし、bundle exec rake db:migrateを実行しようとすると、エラーが出てしまい、それ以降進まなくなっています。もし、わかる方がいらしたら、嬉しいです。
MYSQLのバージョン
mysql Ver 14.14 Distrib 5.7.19, for osx10.12 (x86_64) using EditLine wrapper
問題
== 20190123214656 AddPlansToImages: migrating =================================
-- add_column(:images, :plans, :json)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
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 images ADD plans json
/Users/hiroshi/Desktop/sunny/db/migrate/20190123214656_add_plans_to_images.rb:3:in `change'
Caused by:
ActiveRecord::StatementInvalid: 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 images ADD plans json
/Users/hiroshi/Desktop/sunny/db/migrate/20190123214656_add_plans_to_images.rb:3:in `change'
Caused by:
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
/Users/hiroshi/Desktop/sunny/db/migrate/20190123214656_add_plans_to_images.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Console
1$ rails generate migration AddPlansToImages plans:json 2 3$ rake db:migrate
Gemfile
1source 'https://rubygems.org' 2 3 4# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 5gem 'rails', '4.2.8' 6# Use mysql as the database for Active Record 7gem 'mysql2', '0.3.18' 8# Use SCSS for stylesheets 9gem 'sass-rails', '~> 4.0.2' 10# Use Uglifier as compressor for JavaScript assets 11gem 'uglifier', '>= 1.3.0' 12# Use CoffeeScript for .coffee assets and views 13gem 'coffee-rails', '~> 4.1.0' 14# See https://github.com/rails/execjs#readme for more supported runtimes 15# gem 'therubyracer', platforms: :ruby 16 17# Use jquery as the JavaScript library 18gem 'jquery-rails' 19# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 20gem 'turbolinks' 21# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 22gem 'jbuilder', '~> 2.0' 23# bundle exec rake doc:rails generates the API under doc/api. 24gem 'sdoc', '~> 0.4.0', group: :doc 25 26# Use ActiveModel has_secure_password 27# gem 'bcrypt', '~> 3.1.7' 28 29# Use Unicorn as the app server 30# gem 'unicorn' 31 32# Use Capistrano for deployment 33# gem 'capistrano-rails', group: :development 34 35group :development, :test do 36 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 37 gem 'byebug' 38end 39 40group :development do 41 # Access an IRB console on exception pages or by using <%= console %> in views 42 gem 'web-console', '~> 2.0' 43 44 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 45 gem 'spring' 46end 47 48gem 'pry-rails' 49gem 'compass-rails','~> 2.0' 50gem 'sprockets', '2.11.0' 51#pagenation 52gem 'kaminari' 53#login_logout 54gem 'devise' 55gem 'paperclip' 56 57#chat 58gem 'websocket-rails' 59gem 'faye-websocket', '0.10.0' 60#image 61gem 'carrierwave' 62gem 'rmagick' 63#date 64gem 'momentjs-rails' 65gem 'bootstrap3-datetimepicker-rails'
db/migrate
1class AddPlansToImages < ActiveRecord::Migration 2 def change 3 add_column :images, :plans, :json 4 end 5end
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/24 09:35
2019/01/24 13:22
2019/01/24 13:58
2019/01/24 14:52