[英]Mysql syntaxerror while trying multiple image upload in rails using carrierwave gem
我在這里遵循了載波文件,將多個圖像上傳到我的列表模型。 何時,我使用了命令
rails g migration add_images_to_listings images:json
這樣成功創建了遷移-
class AddImagesToListings < ActiveRecord::Migration
def change
add_column :listings, :images, :json
end
end
但是運行rake db:migrate會引發mysql語法錯誤
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 `listings` ADD `images` json/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:299:in `query'
我懷疑這是因為mysql不支持json數據類型。 有一些解決方法嗎?
如您所見,這里https://dev.mysql.com/doc/refman/5.7/en/json.html
JSON數據類型僅在Mysql 5.7.8或更高版本上可用。
在這里https://github.com/rails/rails/pull/21110
在Rails 5上添加了MySQL JSON類型。
因此,如果您的設置低於這些配置,則不能將JSON與Mysql一起使用。
但是您可以在遷移時使用:text類型來解決此問題:
class AddImagesToListings < ActiveRecord::Migration
def change
add_column :listings, :images, :text
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.