MySQL Forums
Forum List  »  Newbie

Can't create NOT NULL timestamp
Posted by: Jan Kowalski
Date: September 02, 2015 10:53AM

Hi,

I'm trying to create a table with a timestamp field, which doesn't allow null (insert with null should fail). Could someone help, please?

mysql> select @@version;
5.6.24-ndb-7.4.6-cluster-gpl

mysql> SELECT @@sql_mode;
STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

mysql> SELECT @@explicit_defaults_for_timestamp;
1

CREATE TABLE `test` (
`id` int(10) unsigned auto_increment,
`startTime` timestamp NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=ndb;

ERROR 1067 (42000): Invalid default value for 'startTime'


Result is the same for innodb engine.

Documentation states:
https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp

"TIMESTAMP columns declared as NOT NULL and without an explicit DEFAULT clause are treated as having no default value. For inserted rows that specify no explicit value for such a column, the result depends on the SQL mode. If strict SQL mode is enabled, an error occurs."

So what am I missing here?

Options: ReplyQuote


Subject
Written By
Posted
Can't create NOT NULL timestamp
September 02, 2015 10:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.