Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

Error while assigning default value to a datetime field in mysql

HI,
I am getting the following error on creation of a column with type datetime and setting the default value to NOW().
Basicaly i want to create a column in my table so that whenever a new row is inserted it automatically gets populated with the current date and time.
An error occurred when trying to change the field 'created_on' via

ALTER TABLE `retentions` CHANGE `created_on` `created_on` DATETIME
 NULL
 DEFAULT 'NOW()'

MySQL said: Invalid default value for 'created_on'

Open in new window

Whats wrong with this... how can i achieve this..

Thanks
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Arnold is right.  In the table definition you can use CURRENT_TIMESTAMP.  In the SQL query you can use NOW().