【发布时间】:2016-11-20 21:03:03
【问题描述】:
我有迁移:
lass ChangeDefaultValueBodyForBlogPosts < ActiveRecord::Migration
def up
change_column :blog_posts, :body, :text, :null => false
change_column :comments, :text, :text, :null => false
end
def down
change_column :comments, :text, :text, :default => nil
change_column :blog_posts, :body, :text, :default => nil
end
end
rake db:migrate 显示错误:
Mysql2::Error: BLOB, TEXT, GEOMETRY or JSON column 'body' can't have a default value: ALTER TABLE blog_posts CHANGE body body text DEFAULT '' NOT NULL/home /user/projects/projectname/db/migrate/20120508203410_change_default_value_body_for_blog_posts.rb:3:in `up'
我用的是 ubuntu 16.04,
mysql服务器5.7(版本:5.7.12-0ubuntu1.1 版本:5.7.12-0ubuntu1 版本:5.7.11-0ubuntu6 )
我查了谷歌,解决这个问题需要改变
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
到
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
但是 my.conf 文件是空的。
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
如何解决这个问题,请帮忙。谢谢你。
【问题讨论】:
标签: mysql ruby-on-rails ubuntu