如何定义我的struct以在Go中为Gorm指定多列唯一索引? 如: type Something struct {
gorm.Model
First string `sql:"unique_index:unique_index_with_second"`
Second string `sql:"unique_index:unique_index_with_first
我有两个表 type Podcast struct {
Id int
Title string
RssUrl string `sql:"unique_index"`
Episodes []Episode
}
type Episode struct {
Id int
PodcastID int
Title strin
这是我的DB模式: 用户: id uuid PRIMARY KEY , title character
"1234" "ABCD"
语言: id uuid PRIMARY KEY , name character
"1122" "eng"
"1133" "man"
user_languages: user_id uuid, language_id uuid
我想在gorm中使用多对多的关系。但是,该示例是一个部分片段,我尝试创建一个类似的示例代码片断失败。 package main
import (
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
type Part struct {
gorm.Model
Name string
我有以下表格。 nyct2010 和 旅行 我已经定义的模型如下。 type Nyct2010 struct {
Id int `gorm:"column:gid"`
Borocode int
}
type Trip struct {
Id int
PickupLongitude float64 `gorm:"column:pickup_lon
为什么gorm忽略sql:"index"标签?没有索引创建。 这里使用的数据库是PostgreSQL(导入_ "github.com/lib/pq")。这Model结构被使用(因为默认gorm.Model使用自动增量号 - serial - 作为主键,我想成立id自己): type Model struct {
ID int64 `sql:"type:bigint PRIMARY KE