问题
I know that for a DATETIME column you can you CURRENT_TIMESTAMP but what about a DATE column? I don't need hours, minutes and seconds and while trying to set CURRENT_TIMSTAMP as default for I get an error. Thanks
回答1:
A date
or time
type columns can be defined with a default 0
but not a curdate()
or curtime()
.
As per documentation on Data Type Default Values:
The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE.
回答2:
on update CURDATE();
Try this if it works
ALTER TABLE `tablename`
CHANGE `tablename` `tablename`timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
来源:https://stackoverflow.com/questions/22197178/can-a-field-with-date-type-have-a-default-value-with-current-timestamp