string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn't have a default value"

mysql version 5.7.26, an error when inserting data:

string(81) "SQLSTATE[HY000]: General error: 1364 Field 'content' doesn't have a default value"

SQL insert statement:

 INSERT INTO `ent_news` (`title` , `small_title` , `catid` , `description` , `source_type` , `image`) VALUES ('qq' , '' , '101' , '' , '0' , '')

by:

 show create table ent_news;

Construction of the table statement analysis, found that the content field is NOT NULL, shots are as follows:

 

 mysql provides for BLOB, TEXT, GEOMETRY and the JSON, these types of data types are not allowed to have a default value, in this example the content field is not set the default value, after analysis, is the cause of NOT NULL, then the content field set to NULL

alter table ent_news modify column content text null after image;

Table structure is now amended as follows:

 

 Perform an insert statement again, inserted successfully.

There is another solution is to modify the mysql configuration file, sql_mode in STRICT_TRANS_TABLES removed, if such modifications may cause security problems, we do not recommend this modification.

 

Guess you like

Origin www.cnblogs.com/goujian/p/11701287.html