2016-01-02 2 views
2

Я только что установил MySQL Community Server 5.7 и я пытаюсь создать следующую таблицу:MySQL Community 5,7 - недопустимое значение по умолчанию (DateTime тип поля)

CREATE TABLE IF NOT EXISTS `atcommandlog` (
    `atcommand_id` mediumint(9) unsigned NOT NULL auto_increment, 
    `atcommand_date` datetime NOT NULL default '0000-00-00 00:00:00', 
    `account_id` int(11) unsigned NOT NULL default '0', 
    `char_id` int(11) unsigned NOT NULL default '0', 
    `char_name` varchar(25) NOT NULL default '', 
    `map` varchar(11) NOT NULL default '', 
    `command` varchar(255) NOT NULL default '', 
    PRIMARY KEY (`atcommand_id`), 
    INDEX (`account_id`), 
    INDEX (`char_id`) 
) ENGINE=MyISAM AUTO_INCREMENT=1; 

Это дает мне следующее сообщение об ошибке:

#1067 - Invalid default value for 'atcommand_date'

Этот же запрос отлично работает в MySQL 5.6. Было ли изменено значение datetime по умолчанию в MySQL 5.7?

ответ

1

This looks like more of a SQL mode issue than the char set. Strict mode (and more specifically NO_ZERO_DATE which is part of strict mode) usually sets off that error if the table was created with an all zero default date before turning on strict.

What we use (for similar modified date columns), is the '1970-01-01 00:00:01'.

and on a slightly related note, we use timestamp for these columns (and for created time too). Takes half the storage space, and is faster access.

https://dba.stackexchange.com/questions/6171/invalid-default-value-for-datetime-when-changing-to-utf8-general-ci

Смежные вопросы