How to set default date time as system date time in mysql

I am trying to set the default time for columns in system datetime. It shows me a mistake

Invalid default value for 'InsertionDate'

alter table `vts`.`tblpickpoint` add column `InsertionDate` datetime DEFAULT 'Now()' NULL after `PickPointLatLong` 
+4
source share
3 answers

The default value for a column in mysql cannot be the result of a function.

The only exception is current_timestamp, as indicated by the observer.

Your expression should be

 alter table `vts`.`tblpickpoint` add column `InsertionDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP 
+2
source

Look at CURRENT_TIMESTAMP

+2
source

If you want to initialize and update the value with every change, use this:

 alter table `vts`.`tblpickpoint` add column `InsertionDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP after `PickPointLatLong` 

If you want only creation time, use this:

 alter table `vts`.`tblpickpoint` add column `InsertionDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP after `PickPointLatLong` 
0
source

Source: https://habr.com/ru/post/1306013/


All Articles