Home php教程 php手册 MySQL 1364 错误解决办法

MySQL 1364 错误解决办法

Jun 06, 2016 pm 08:00 PM
mysql php Method solve mistake

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";  
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

How to fix mysql_native_password not loaded errors on MySQL 8.4

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles