“日期"的默认值无效 [英] Invalid default value for 'Date'

查看:115
本文介绍了“日期"的默认值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将日期设置为mysql中日期的默认值(不是时间戳),但是出现以下错误

I want to set date as default value for date in mysql (not timestamp), but the following error appear

ALTER TABLE `RMS`.`transactionentry` 
CHANGE `Date` `Date` DATE DEFAULT NOW() NOT NULL

错误

Invalid default value for 'Date'

相同的情况

alter table `RMS`.`transactionentry` 
change `Date` `Date` date default 'CURRENT_DATE' NOT NULL

推荐答案

alter table `RMS`.`transactionentry`
change `Date` `Date` date default current_timestamp NOT NULL

已更新:

我认为您无法使用mysql date来实现.您必须使用timestamp或尝试这种方法.

Updated:

I don't think you can achieve that with mysql date. You have to use timestamp or try this approach..

CREATE TRIGGER transactionentry_OnInsert BEFORE INSERT ON `RMS`.`transactionentry`
    FOR EACH ROW SET NEW.dateColumn = IFNULL(NEW.dateColumn, NOW());

这篇关于“日期"的默认值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆