先说结论
int类型和varchar类型字段默认值插入时机:插入语句不写该字段
且int类型字段不允许插入空白字符串
下面是测试过程
创建表
CREATE TABLE `tb_test_tigger` (
`id` bigint(20) NOT NULL,
`testint_no` int(11) DEFAULT 0 COMMENT '测试不写该字段是否可以插入',
`testint_null` int(11) DEFAULT 0 COMMENT '测试字段为null是否可以插入',
`testint_kongbai` int(11) DEFAULT 0 COMMENT '测试字段为空白字符串是否可以插入',
`test_no` varchar(2) DEFAULT '0' COMMENT '测试不写该字段是否可以插入',
`test_null` varchar(2) DEFAULT '0' COMMENT '测试字段为null是否可以插入',
`test_kongbai` varchar(2) DEFAULT '0' COMMENT '测试字段为空白字符串是否可以插入',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='测试触发器';
插入语句
insert into tb_test_tigger
(id,testint_null,testint_kongbai,test_null,test_kongbai)
values
(1,null,'',null,'')
插入结果
SQL 错误 [1366] [HY000]: Incorrect integer value: '' for column 'testint_kongbai' at row 1
修改插入语句
insert into tb_test_tigger
(id,testint_null,test_null,test_kongbai)
values
(1,null,null,'')