首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mysql2 2::Error: BLOB、TEXT、几何学或JSON列'body‘不能有默认值

Mysql2 2::Error: BLOB、TEXT、几何学或JSON列'body‘不能有默认值
EN

Stack Overflow用户
提问于 2016-07-18 09:50:33
回答 6查看 29.3K关注 0票数 8

我有移民:

代码语言:javascript
复制
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:迁移显示错误:

错误: BLOB、TEXT、几何图形或JSON列'body‘不能有默认值: ALTER blog_posts CHANGE body body text默认值’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“

代码语言:javascript
复制
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

但是my.conf文件是空的。

代码语言:javascript
复制
#
# 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/

如何解决这个问题,请帮助。谢谢。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2016-09-17 17:57:52

您需要找到正确的my.cnf:

代码语言:javascript
复制
sudo find / -name "*.cnf"

/etc/mysql/mysql.conf.d/mysqld.cnf
/etc/mysql/my.cnf
/etc/mysql/mysql.cnf
/etc/mysql/conf.d/mysqldump.cnf
/etc/mysql/conf.d/mysql.cnf

我编辑了/etc/mysql/mysql.conf/mysqld.cnf

代码语言:javascript
复制
strace mysql ";" 2>&1  | grep cnf

stat("/etc/my.cnf", 0x7ffda9472660)     = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=683, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY)     = 3
stat("/etc/mysql/conf.d/mysql.cnf", {st_mode=S_IFREG|0644, st_size=8, ...}) = 0
open("/etc/mysql/conf.d/mysql.cnf", O_RDONLY) = 4
stat("/etc/mysql/conf.d/mysqldump.cnf", {st_mode=S_IFREG|0644, st_size=55, ...}) = 0
open("/etc/mysql/conf.d/mysqldump.cnf", O_RDONLY) = 4
stat("/etc/mysql/mysql.conf.d/mysqld.cnf", {st_mode=S_IFREG|0644, st_size=3034, ...}) = 0
open("/etc/mysql/mysql.conf.d/mysqld.cnf", O_RDONLY) = 4
stat("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
open("/etc/mysql/mysql.conf.d/mysqld_safe_syslog.cnf", O_RDONLY) = 4
stat("/root/.my.cnf", 0x7ffda9472660)   = -1 ENOENT (No such file or directory)
stat("/root/.mylogin.cnf", 0x7ffda9472660) = -1 ENOENT (No such file or directory)

找到正确的文件后,在mysqld语句下面添加sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

票数 1
EN

Stack Overflow用户

发布于 2016-07-18 10:21:16

我找到了解决方案:需要添加my.cnf

代码语言:javascript
复制
[mysqld]
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
票数 1
EN

Stack Overflow用户

发布于 2019-10-27 23:10:25

在本地机器上使用xampp的mysql进行迁移没有问题。只有在生产服务器上,它才开始失败。我发现xampp运行的是mariadb而不是普通的mysql。因此,在服务器上使用mariaDB解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38433603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档