mysql错误1364字段没有默认值 [英] mysql error 1364 Field doesn'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字段没有默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文