2016-09-06 37 views
0

有表customer_accountpostgres)哪一個是從YII2遷移的。Golang:gorm use尋找非模板遷移表(&)

DDL:

CREATE TABLE public.test_table (
    id INTEGER PRIMARY KEY NOT NULL DEFAULT nextval('test_table_id_seq'::regclass), 
    data JSONB 
); 

在旅途中的項目,我試圖從該表中獲取價值。

type TableGo struct { 
    Id int 
    Data string `gorm:"type:jsonb"` 
} 

    table := TableGo{} 
    db.Where("id = ?", 75).Find(&table) 
    println(table.Data) 

但有(pq: relation "table_gos" does not exist)

如何我可以鏈接結構表,而db.AutoMigrate(&TableGo{})

回答

0

我想在你的遷移腳本表名是錯誤的。因爲它不符合GORM慣例。如果您想使用該名稱,則可以在模型中使用以下方法來定製表名。

func (m *Model) TableName() string { 
    return "custom_table_name" 
} 
0

找到了解決辦法:

func(TableGo) TableName() string { 
    return "account_status" 
}