我正在和戈姆一起开发一款杜松子wine 应用程序.目前,我有以下代表模型的 struct :
// Category represents a category object in the database
type Category struct {
Name string `json:"name" gorm:"size:60,unique,not null"`
Description string `json:"description" gorm:"size:120"`
Parent uint `json:"parent"`
Active bool `json:"active" gorm:"default:true"`
gorm.Model
}
如您所见,存在一些约束,例如size
、unique
和not null
.
当我运行迁移时
该表实际上是创建的,但不具有指定的约束.
CREATE TABLE `categories` (
`name` longtext DEFAULT NULL,
`description` varchar(120) DEFAULT NULL,
`parent` int(10) unsigned DEFAULT NULL,
`active` tinyint(1) DEFAULT 1,
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_categories_deleted_at` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
知道我做错了什么吗?