You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As defined in the gorm documentation. I set the default value of these fields to 0 and auto-populate the current timestamp when creating or updating.
but it doesn't seem to work. If I remove the default values the logic of auto-populating the current timestamp will work.
`
package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type AutoTime struct {
ID int
Create_time int64 gorm:"autoCreateTime;default:0;not null"
Update_time int64 gorm:"autoUpdateTime;default:0;not null"
Delete_time int64 gorm:"default:0;not null"
}
The document you expected this should be explained
In the above code I have created a data model and corresponding field definitions.
Then I inserted a piece of data, expecting both create_time and update_time to be the current timestamp.
However, after creation they are both 0, and only after updating are the values of update_time updated to the current timestamp.
Expected answer
I want both create_time and update_time to be the current timestamp after creation. Is there something wrong with my usage?
The text was updated successfully, but these errors were encountered:
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 ✨
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 ✨
autoUpdateTime and default seem to be conflicting
As defined in the gorm documentation. I set the default value of these fields to 0 and auto-populate the current timestamp when creating or updating.
but it doesn't seem to work. If I remove the default values the logic of auto-populating the current timestamp will work.
`
package main
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
type AutoTime struct {
ID int
Create_time int64
gorm:"autoCreateTime;default:0;not null"
Update_time int64
gorm:"autoUpdateTime;default:0;not null"
Delete_time int64
gorm:"default:0;not null"
}
func main() {
dsn := "root:root@tcp(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
db.AutoMigrate(&AutoTime{})
}
`
The document you expected this should be explained
In the above code I have created a data model and corresponding field definitions.
Then I inserted a piece of data, expecting both create_time and update_time to be the current timestamp.
However, after creation they are both 0, and only after updating are the values of update_time updated to the current timestamp.
Expected answer
I want both create_time and update_time to be the current timestamp after creation. Is there something wrong with my usage?
The text was updated successfully, but these errors were encountered: