我有一张桌子
CREATE TABLE `devicelist` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
`serial` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`networkname` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
`login` varchar(130) COLLATE utf8_unicode_ci DEFAULT NULL,
`password` varchar(130) COLLATE utf8_unicode_ci DEFAULT NULL,
`peopleid` int(10) unsigned NOT NULL,
`deviceid` int(10) unsigned NOT NULL,
`placeid` int(10) unsigned NOT NULL,
`stationid` int(10) unsigned NOT NULL,
`place` text COLLATE utf8_unicode_ci,
`date` date NOT NULL,
`active` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `placeid` (`placeid`),
KEY `stationid` (`stationid`),
KEY `peopleid` (`peopleid`),
KEY `deviceid` (`deviceid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
如您所见,序列设置为NOT NULL,
但是当我运行查询时
UPDATE DeviceList SET serial = NULL WHERE id = 1
它输出
1 row affected. ( Query took 0.0079 sec )
为什么将 null 插入非 null 字段?
我希望发生错误:D
///****************************** 编辑
好吧,我找到了答案
,问题出在 sql_mode
https://dev.mysql.com/doc/refman/5.6/en/sql-mode.html#sql-mode-strict
我的 sql_mode 默认为空,我
将其更改为 STRICT_ALL_TABLES通过
SET GLOBAL sql_mode='STRICT_ALL_TABLES'