Invalid default value for 'Date'

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

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
+5
source share
4 answers
alter table `RMS`.`transactionentry`
change `Date` `Date` date default current_timestamp NOT NULL

Updated:

I do not think you can achieve this with mysql date. You should use timestampor try this approach.

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

DEFAULT . ; . , , , NOW() CURRENT_DATE. , CURRENT_TIMESTAMP TIMESTAMP.

: . dev.mysql.com

+8

MySQL:

DEFAULT . ; . , , , NOW() CURRENT_DATE. - CURRENT_TIMESTAMP TIMESTAMP.

:

alter table `RMS`.`transactionentry` 

change `Date` `Date` date default CURRENT_TIMESTAMP NOT NULL

. , , .

+1

Remember that this may be a problem with the version of MYSQL 5.6 itself allows you to mark a timestamp with a default value and does not require it to be set to null, but 5.7 requires you to explicitly set a default value, if not then nul

0
source

All Articles