Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type标签无法指定time类型? #6033

Closed
congjunhua opened this issue Feb 6, 2023 · 7 comments · Fixed by go-gorm/sqlite#133 · May be fixed by go-gorm/postgres#160 or go-gorm/bigquery#14
Closed

type标签无法指定time类型? #6033

congjunhua opened this issue Feb 6, 2023 · 7 comments · Fixed by go-gorm/sqlite#133 · May be fixed by go-gorm/postgres#160 or go-gorm/bigquery#14
Assignees

Comments

@congjunhua
Copy link

通过type标签指定AtTime类型:

type Test struct {
	At string `gorm:"type:time"`
}

AutoMigrate时却使用了datetime类型:

[3.979ms] [rows:0] CREATE TABLE `tests` (`at` datetime(3) NULL)
@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Feb 6, 2023
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

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.ioSearch Before Asking

@congjunhua
Copy link
Author

congjunhua commented Feb 6, 2023

临时解决方案:

db.AutoMigrate(&model.Test{})

db.Exec("alter table tests modify at time null")

望修复。

@github-actions
Copy link

github-actions bot commented Feb 6, 2023

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.ioSearch Before Asking

@a631807682
Copy link
Member

@congjunhua
Copy link
Author

congjunhua commented Feb 8, 2023

为了这个小问题再引入一个自定义类型的包我感觉是不合适的,因为本质上标签无法指定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)

@a631807682
Copy link
Member

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

@black-06
Copy link
Contributor

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

black-06 added a commit to black-06/gorm that referenced this issue Feb 20, 2023
@black-06 black-06 mentioned this issue Feb 20, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment