我正在尝试将我的数据库的日期时间列转换为时间戳而不会丢失数据。我遵循了这个答案: Bulk convert and update datetime column values to UNIX timestamp?
但是当我想:
UPDATE `members` SET `new_join_date` = UNIX_TIMESTAMP(`join_date`), `new_last_visit` = UNIX_TIMESTAMP(`last_visit`);
我收到此错误:
#1292 - Incorrect datetime value: '1376833381' for column 'new_join_date' at row 1
完整的转换查询:
ALTER TABLE `members`
ADD COLUMN `new_join_date` TIMESTAMP NULL AFTER `join_date`,
ADD COLUMN `new_last_visit` TIMESTAMP NULL AFTER `last_visit`;
UPDATE `members`
SET `new_join_date` = UNIX_TIMESTAMP(`join_date`),
`new_last_visit` = UNIX_TIMESTAMP(`last_visit`);
ALTER TABLE `members` DROP `join_date`;
ALTER TABLE `members` DROP `last_visit`;
ALTER TABLE `members` CHANGE `new_join_date` `join_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE `members` CHANGE `new_last_visit` `last_visit` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;