Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid default value for 'Date'

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

Error

Invalid default value for 'Date'

Same Case

alter table `RMS`.`transactionentry` 
change `Date` `Date` date default 'CURRENT_DATE' NOT NULL
like image 776
Shahid Ghafoor Avatar asked Jul 20 '12 05:07

Shahid Ghafoor


1 Answers

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

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());
like image 53
manurajhada Avatar answered Oct 29 '22 07:10

manurajhada