当前位置:网站首页>Go Gorm MySQL reports an error: error 1292: incorrect datetime value: 'xxx' for column 'created_ at‘ at row 1
Go Gorm MySQL reports an error: error 1292: incorrect datetime value: 'xxx' for column 'created_ at‘ at row 1
2022-07-22 01:36:00 【Clear smoke】
The problem record
In use go When writing project operation database in language , Because of my User There is a time field in the structure
type User struct {
ID uint `gorm:"primary_key"`
CreatedAt time.Time `gorm:"type:timestamp;not null"`
UpdatedAt time.Time `gorm:"type:timestamp;not null"`
UserName string `gorm:"type:varchar(20);not null" json:"username"`
PassWord string `gorm:"type:varchar(20);not null" json:"password"`
Role int `gorm:"type:int" json:"role"`
}
Then I made an error in updating the database
err := db.Create(&data).Error
Error 1292: Incorrect datetime value: '2022-07-20 15:52:42.7744207' for column 'created_at' at row 1
From the perspective of error reporting, it is probably illegal because the type of value does not correspond to the value
So I changed the value type to datatime and timestamp
Neither. , So I went to check the information
resolvent
This link solves my problem , But what the owner of the link solves is that time cannot be 0, I also encountered at the beginning , Later, I didn't understand the solution, so I gave up the one that was originally in my project del_at Field .
The main cause of the problem is mysql Caused by the strict mode of .
resolvent
see sql_mode
# View the current sql_mode
select @@sql_mode;
# Look at the big picture sql_mode
select @@global.sql_mode;
mysql> select @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select @@global.sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@global.sql_mode |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
modify sql_mode
Don't write like the following , As long as you put your sql_mode Medium STRICT_TRANS_TABLES Just remove the field ok 了
# Modify global
set @@global.sql_mode = 'ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
# Modify the current
set @@sql_mode = 'ONLY_FULL_GROUP_BY,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
边栏推荐
- Advantages and disadvantages of Tongniu computer room project
- [dongle vulnerability notification] Apache spark command injection vulnerability scheme
- C语言经典一百题(1-10题)(含答案)
- Interrupt vector table in stm32
- 学习路之PHP--thinkphp5+windows服务器实现定时任务
- PO模式在Selenium自动化测试中怎么应用
- Using completable future to implement asynchronous callback
- 阿里面试应该注意什么?通过5轮面试的阿里实习生亲述
- The NSLOOKUP command uses
- AidLux
猜你喜欢
Reprint: can bus terminal resistance
Hardcore Fiddler packet capturing tool large strategy (end) Fiddler ultimate
Learn the necessary tools of automation selenium think about automated testing in the pit again
(pytorch advanced road VI) implementation of swing transformer
A 股分笔交易数据 API 数据接口
NetworkX的基本用法
记一次远程Debug调试Minecraft服务器插件经历
AidLux
【集训DAY6】Triangle【数学】【暴力】
3、Nacos 配置中心源码解析之 项目结构
随机推荐
[Yugong series] go teaching course in July 2022 014 arithmetic operators of operators
idea运行@test不能从控制台输入,处于加载状态
氟尼辛肽核酸寡聚体复合物|规活性基团Alkyne炔烃,SH Thiol炔基修饰肽核酸
1、Nacos 配置中心源码解析之 Hello World
44: Chapter 4: develop file service: 5: integrate fastdfs in [files] file service to realize the logic of [upload avatar]; (including: integrating fastdfs in the project; cross domain issues; creating
重大突破!首款国产科学计算软件研发成功
I.MX6U-ALPHA开发板(蜂鸣器实验)
SSM integrates other components
tinymce 去掉编辑器换行默认增加的p标签
小程序 奇葩BUG 更新~
新知识经济时代,谁在生产知识?
I.MX6U-ALPHA开发板(按键输入实验)
Problems and principle analysis of audio AGC
【学习笔记】AGC008
动态规划背包问题——01背包
【集训DAY8】Series【矩阵乘法】
“我放弃编程,写了一本130万字的硬科幻小说”
LeetCode 1928. 规定时间内到达终点的最小花费
转载:CAN总线终端电阻
C语言经典一百题(1-10题)(含答案)