MySQL 的 某个字段数据类型为ENUM, 为这个字段设置默认值后,新插入数据后,为什么不会自动填充默认值?
大家讲道理
大家讲道理 2017-04-17 13:37:32
0
2
349

如题,我在一张表里设计了这样一张字段,枚举集合为('used','receive','invalid','deleted'),设置了默认字段receive,并且设置非空,sql语句如下:

`status` enum('used','receive','invalid','deleted') CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'receive' COMMENT '使用状态'

当我在实际插入数据的时候,并没有去设置这个字段的值,结果是插入可以成功,但是查看插入数据的时候,发现这个字段的值为空,难道我设置了默认值,他不会自动把receive填充进去的吗?还有我之前设置了非空,那个字段显示为空,但是竟然插入成功了,这是为什么呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
迷茫

Have you used an ORM? Check to see if the model in your ORM has a default value configured

Post the result of your show create table
Post the SQL statement that failed to insert

阿神

Just don’t write this field when inserting~ Don’t write insert into tb values(1,2,3,null); instead write insert into tb (a,b,c) values(1,2,3 ), in this case the status will be inserted into the default value receive

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!