我正在遵循carrierwave文档here将多张图片上传到我的列表模型中。当我使用命令时,
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数据类型。有什么变通方法吗?
发布于 2016-05-19 00:24:39
正如你在这里看到的,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
endhttps://stackoverflow.com/questions/32866305
复制相似问题