码迷,mamicode.com
首页 > 其他好文 > 详细

Tips on GORM, Avoid Error about "duplicate column name: id"

时间:2018-04-15 20:54:36      阅读:581      评论:0      收藏:0      [点我收藏+]

标签:create   mod   dup   get   people   this   jin   void   highlight   

The GORM is an super easy ORM solution for Go language.

But many people would get the error about 

duplicate column name: id

Usually this comes from the model definition which has duplicated ID,

package model

import (
    "github.com/jinzhu/gorm"
)

type Job struct {
    gorm.Model // Already has ID, CreatedAt, UpdatedAt, DeletedAt 4 fields
    Name string
}

We could remove the ID definition from our code and only use the one from grom.Model, or don‘t use the gorm.Model at all.

Tips on GORM, Avoid Error about "duplicate column name: id"

标签:create   mod   dup   get   people   this   jin   void   highlight   

原文地址:https://www.cnblogs.com/Jedimaster/p/8849013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!