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 (
    "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.

posted on 2018-04-15 19:14  Bo Schwarzstein  阅读(532)  评论(0编辑  收藏  举报