本文介绍了SQL查询不适用于RDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是表的定义:

CREATE TABLE IF NOT EXISTS `updated_tables` (
  `table_name` VARCHAR(50) NOT NULL,
  `updated_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
  PRIMARY KEY (`table_name`),
  UNIQUE INDEX `table_name_UNIQUE` (`table_name` ASC))
  ENGINE = InnoDB;

这是查询(由Sequalize生成):

This is the query (Generated by Sequalize):

INSERT INTO `updated_tables` (`table_name`,`updated_at`) VALUES ('workdamnit',NULL) ON DUPLICATE KEY UPDATE `table_name`=VALUES(`table_name`), `updated_at`=VALUES(`updated_at`);

同一查询的简化形式:

INSERT INTO `updated_tables` (`table_name`,`updated_at`) VALUES ('workdamnit',NULL)

它会在表中产生以下条目:

And it produces the following entry in table:

表名称: workdamnit

updated_at: 2018-07-05 14:27:17.142494

updated_at: 2018-07-05 14:27:17.142494

现在要提问.

给出此错误:错误代码:1048.列'updated_at'不能为空

是因为MySQL版本有所不同,还是必须对RDS做一些事情?

Is it since the MySQL versions are a bit different, or it has to do something with RDS?

推荐答案

经过研究,我找到了答案.默认情况下,RDS实例具有严格模式,因此它响应正确.虽然我的本地实例以及EC2上的MySQL实例都没有使用严格模式.

After some research I found the answer. The RDS instance has a strict mode turned on by default, so it was responding properly. While my local instance, and also an instance of MySQL on EC2, were not using the strict mode.

这篇关于SQL查询不适用于RDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 18:07
查看更多