Home > php教程 > php手册 > body text

MySQL 1364 错误解决办法

WBOY
Release: 2016-06-06 20:00:57
Original
3161 people have browsed it

MySQL 1364 错误提示:#1364 - Field "details" doesn't have a default value。大概意思是:details字段没有默认的数值;也就是说我们没有为其分配数值,而表中此字段也没有设置默认值。这是MySQL5出来后搞出来的东东,认真看一下my.ini文件中有这样一段:

MySQL 1364 错误提示:#1364 - Field "details" doesn't have a default value。大概意思是:details字段没有默认的数值;也就是说我们没有为其分配数值,而表中此字段也没有设置默认值。这是MySQL5出来后搞出来的东东,认真看一下my.ini文件中有这样一段:

my.ini中相关代码

  1. # Set the SQL mode to strict
  2. # sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
  3. sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

假如您无法看到my.ini,你可以执行以下SQL命令。

SQL代码

  1. SELECT @@GLOBAL.sql_mode;  

您可能一下子就注意到:STRICT_TRANS_TABLES(存储引擎启用严格模式,非法数据值被拒绝)。这也就是为什么我们插入数据时返回1364的原因:details字段没有设置默认值。

解决办法有两种:

第一种:数据库设计时,为可能没有数据的字段设置默认值。

第二种:设置SQL的模式,此有两种方法:

(1),配置my.ini,去掉:STRICT_TRANS_TABLES

my.ini配置代码

  1. # Set the SQL mode to strict
  2. # sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
  3. sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

(2),运行SQL命令。注:此命令需要权限!

SQL代码

  1. SET @@GLOBAL.sql_mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";  
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!