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

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 (

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.

posted @ 2018-04-15 19:14 Bo Schwarzstein 阅读(...) 评论(...) 编辑 收藏