【发布时间】:2020-03-21 20:53:46
【问题描述】:
我有以下 2 个gorm 模型
// Day is a corresponding day entry
type Day struct {
gorm.Model
Dateday string `json:"dateday" gorm:"type:date;NOT NULL"`
Nameday string `json:"nameday" gorm:"type:varchar(100);NOT NULL"`
Something sql.NullString `json:"something"`
Holyday bool `json:"holyday"`
}
type Week struct {
gorm.Model
Start Day
End Day
}
但是,在执行迁移之后
db.AutoMigrate(&Day{})
db.AutoMigrate(&Week{})
登录数据库并描述表weeks
postgres-# \d+ weeks;
Table "public.weeks"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
------------+--------------------------+-----------+----------+-----------------------------------+---------+--------------+-------------
id | integer | | not null | nextval('weeks_id_seq'::regclass) | plain | |
created_at | timestamp with time zone | | | | plain | |
updated_at | timestamp with time zone | | | | plain | |
deleted_at | timestamp with time zone | | | | plain | |
Indexes:
"weeks_pkey" PRIMARY KEY, btree (id)
"idx_weeks_deleted_at" btree (deleted_at)
我没有看到 start / end 字段,这应该也是 day 表的外键(确实存在)
这是为什么呢?
【问题讨论】: