通过type标签指定At为Time类型:
type Test struct {
At string `gorm:"type:time"`
}
但AutoMigrate时却使用了datetime类型:
[3.979ms] [rows:0] CREATE TABLE `tests` (`at` datetime(3) NULL)
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: congjunhua
临时解决方案:
db.AutoMigrate(&model.Test{})
db.Exec("alter table tests modify at time null")
望修复。
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
https://github.com/go-gorm/datatypes#time
Comment From: congjunhua
为了这个小问题再引入一个自定义类型的包我感觉是不合适的,因为本质上标签无法指定time类型这个问题并没有解决。
同时,date没问题,time却有问题,为什么不一致?
我认为应该从造成这种不一致的原因的地方去尝试解决。
type Test struct {
Date time.Time `gorm:"type:date;not null"`
Time time.Time `gorm:"type:time;not null"`
}
CREATE TABLE `tests` (`date` date NOT NULL,`time` datetime(3) NOT NULL)
Comment From: a631807682
Bug due to no distinction between gorm type time.Time and tag type:time
https://github.com/go-gorm/mysql/blob/master/mysql.go#L356
Comment From: black-06
These jobs are all the same :(
Or do we change schema.Time from "time" to "go_time"?
The downside is that the old version of the drivers cannot work with the modified gorm