can somebody please explain why the following is happening? When I run this statement:
CREATE TABLE `MyTable2` (
`id` int(10) unsigned NOT NULL,
`start` timestamp NOT NULL,
`cTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
I get my table created. But when I run this one:
CREATE TABLE `MyTable2` (
`id` int(10) unsigned NOT NULL,
`start` timestamp NOT NULL,
`end` timestamp NOT NULL,
`cTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
I get an error stating:
[42000][1067] Invalid default value for 'end'
What am I missing? Is this the expected behaviour?
[Update]: It seems that there's a filed bug here https://bugs.mysql.com/bug.php?id=80163 but I can not make anything out of the description. Silencing the warnings and/or changing the sql_mode is not a solution as it changes the semantics of the created table (two timestamp columns not null with no default).
[Update]: The sql_mode on my server is as follows:
ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,
NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[Solution/Explanation]: Turns out that here https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp this behaviour is explained in detail. In order to get the expected semantics, I had to enable sysvar_explicit_defaults_for_timestamp in my server's configuration.
set @@sql_mode = ''and then execute your CREATE TABLE command, this may resolve your issueCREATE TABLE annotation (`created` TIMESTAMP NOT NULL, `ts` TIMESTAMP NOT NULL);and the resulting table has defaults.