1

I have the table chart_data:

CREATE TABLE `chart_data` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `type` ENUM('BID', 'ASK') NOT NULL,
    `volume` FLOAT UNSIGNED NOT NULL,
    `tokens` FLOAT UNSIGNED NOT NULL,
    `create_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `id_UNIQUE` (`id`)
)  ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=LATIN1;

When I insert some records an error occurs. For example:

# OK:
INSERT INTO `chart_data` (`type`, `volume`, `tokens`, `create_at`) VALUES ('BID', '1', '1', '2017-03-26 02:05:01');
# Error (+1h):
INSERT INTO `chart_data` (`type`, `volume`, `tokens`, `create_at`) VALUES ('BID', '1', '1', '2017-03-26 03:05:01');
# Error:
INSERT INTO `chart_data` (`type`, `volume`, `tokens`, `create_at`) VALUES ('BID', '1', '1', '2017-03-26 03:59:59');
# OK:
INSERT INTO `chart_data` (`type`, `volume`, `tokens`, `create_at`) VALUES ('BID', '1', '1', '2017-03-26 04:05:01');
# OK (+1d):
INSERT INTO `chart_data` (`type`, `volume`, `tokens`, `create_at`) VALUES ('BID', '1', '1', '2017-04-26 03:05:01');

As I understand, the error only occurs on 2017-03-26 at 3 am.

Error stack trace:

Executing:
UPDATE `gdmv`.`chart_data` SET `create_at`='2017-03-26 03:05:01' WHERE `id`='3';

Operation failed: std::exception
ERROR 1292: 1292: Incorrect datetime value: '2017-03-26 03:05:01' for column 'create_at' at row 1
SQL Statement:
UPDATE `gdmv`.`chart_data` SET `create_at`='2017-03-26 03:05:01' WHERE `id`='3'

What could be the problem?

My environment:

  • mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64)
  • PHP 5.6.26 (cli) (built: Sep 15 2016 15:07:33)
  • Red Hat Enterprise Linux Server release 5.11 (Tikanga)

1 Answers1

0

The format you are trying to input is a datetime format, so you need to change from timestamp to datetime in your sql schema.

Therefore you need to alter your table:

ALTER TABLE chart_data CHANGE create_at datetime NOT NULL DEFAULT 'CURRENT_TIMESTAMP'

or if you prefer full schema

CREATE TABLE `chart_data` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `type` ENUM('BID', 'ASK') NOT NULL,
    `volume` FLOAT UNSIGNED NOT NULL,
    `tokens` FLOAT UNSIGNED NOT NULL,
    `create_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    UNIQUE KEY `id_UNIQUE` (`id`)
)  ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=LATIN1;
Simos Fasouliotis
  • 1,383
  • 2
  • 16
  • 35