Golang GORM: 如何将 struct 字段映射为 MySQL 的 NOT NULL datetime 类型
{"title":"Golang GORM: 如何将 struct 字段映射为 MySQL 的 NOT NULL datetime 类型", "description":"本文介绍了如何在使用 Golang GORM 时将 struct 字段映射为 MySQL 的 NOT NULL datetime 类型,并解释了如何使用 gorm 标签设置约束。", "keywords":"golang, gorm, mysql, datetime, not null, struct, time.Time, 约束, 映射", "content":"在定义一个 struct 时,如果要将 UpTime 字段设置为 not null 并将其映射到 MySQL 的 datetime 类型,可以将字段类型设置为 time.Time,如下所示:\n\ngo\ntype YourStruct struct {\n UpTime time.Time `gorm:\"not null\"`\n}\n\n\n注意,使用 GORM 时,可以通过在字段的 gorm 标签中指定约束来设置 not null。"}
原文地址: https://www.cveoy.top/t/topic/pKRY 著作权归作者所有。请勿转载和采集!