mysql error 1364 Field doesn#39;t have a default values(mysql 错误 1364 字段没有默认值)
问题描述
我的桌子看起来像
create table try ( name varchar(8), CREATED_BY varchar(40) not null);
然后我有一个触发器来自动填充 CREATED_BY 字段
and then I have a trigger to auto populate the CREATED_BY field
create trigger autoPopulateAtInsert BEFORE INSERT on try for each row set new.CREATED_BY=user();
当我使用
insert into try (name) values ('abc');
输入已在表中,但我仍然收到错误消息
the entry is made in the table but I still get the error message
Field 'CREATED_BY' doesn't have a default value Error no 1364
有没有办法在不使字段为空且不删除触发器的情况下抑制此错误?否则我的休眠会看到这些异常(即使已经进行了插入),然后应用程序将崩溃.
Is there a way to suppress this error without making the field nullable AND without removing the triggfer? Otherwise my hibernate will see these exceptions ( even though the insertions have been made) and then application will crash.
推荐答案
为 Created_By
设置一个默认值(例如:空 VARCHAR
),触发器将更新该值无论如何.
Set a default value for Created_By
(eg: empty VARCHAR
) and the trigger will update the value anyways.
create table try (
name varchar(8),
CREATED_BY varchar(40) DEFAULT '' not null
);
这篇关于mysql 错误 1364 字段没有默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mysql 错误 1364 字段没有默认值


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01