Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to set my columns default date time to system datetime. It shows me an error

Invalid default value for 'InsertionDate'

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` 
      datetime DEFAULT 'Now()' NULL after `PickPointLatLong`
like image 933
Shantanu Gupta Avatar asked Apr 05 '10 09:04

Shantanu Gupta


2 Answers

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

The one exception is the current_timestamp as astander points out.

Your statement should be

alter table `vts`.`tblpickpoint` 
  add column `InsertionDate` TIMESTAMP 
             DEFAULT CURRENT_TIMESTAMP 
like image 182
lexu Avatar answered Nov 09 '22 13:11

lexu


Have a look at CURRENT_TIMESTAMP

like image 2
Adriaan Stander Avatar answered Nov 09 '22 14:11

Adriaan Stander