There’s something very irritating going on with my TIMESTAMPS …
I have a “createdat”, “deletedat” and “updatedat” column in my Table… I’ve set my deletedat and updated at to NULL and DEFAULT NULL … however, when a new record is added, the NOW() function is always executed for deletedat and updatedat instead of just leaving it as NULL.
So I end up with: 00:00:00 …
Why isn’t it just defaulting to NULL?
Here’s my Table:

Here’s when Inserting (notice the NOW function is selected):

The following SQL is executed:
INSERT INTO `MYTABLE_DEV`.`messages` (`id`, `fromUserId`, `toUserId`, `subject`, `body`, `createdat`, `updatedat`, `deletedat`) VALUES (NULL, '1', '3', 'Message', 'This is another message.', CURRENT_TIMESTAMP, NOW(), NOW());
This is expected behaviour.
Unlike other databases, in MySQL
TIMESTAMPcolumns are ALWAYS updated withnow()whenever the row is updated. This is a deliberate feature of the TIMESTAMP datatype.Edit: Note that I am talking here about
TIMESTAMP, notTIMESTAMP DEFAULT NULLor any other variations.What you want is a
DATETIMEdatatype – they behave as normal columns.Here’s some test SQL to show its behaviour: