Mysql2::错误:BLOB、TEXT、GEOMETRY或JSON列';车身';can';没有默认值

Mysql2::错误:BLOB、TEXT、GEOMETRY或JSON列';车身';can';没有默认值,mysql,ruby-on-rails,ubuntu,Mysql,Ruby On Rails,Ubuntu,我有以下几点: 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 :com

我有以下几点:

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
但是我的.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/
如何解决这个问题,请帮忙。多谢各位

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

[mysqld]
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

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

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.d/mysqld.cnf

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]语句下面找到正确的文件addsql mode=“NO_AUTO\u CREATE\u USER,NO_ENGINE\u SUBSTITUTION”,我就可以在本地机器上从xampp使用mysql进行迁移了。仅在生产服务器上,它开始出现故障。我发现xampp运行的是mariadb而不是普通的mysql。因此,在服务器上使用mariaDB修复了我的问题。

再次检查sql代码错误上面清楚地说“body”不是默认值
示例:

 `completed` text NOT NULL  DEFAULT 'false',
删除默认值后

`completed` text NOT NULL,
现在希望你的错误消失了。
对不起我的英语。

我这样解决了这个问题:我曾经想在一台服务器上导出我的mySql数据库,然后将它导入另一台服务器(CPanel主机)。每次我尝试时,phpMyAdmin总是在一个数据库表的一个字段上给出这个错误。然后我去了我的源主机;打开phpMyAdmin并打开该表结构,并删除该字段的默认值。然后我再次导出,这一次成功了。

注意:如果依赖于查询,这可能会破坏代码,如果您输入字段
completed
,它将获得默认值。您也必须相应地调整代码
`completed` text NOT NULL,