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

Posted Die feuchter Einsamkeit

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.

以上是关于Tips on GORM, Avoid Error about "duplicate column name: id"的主要内容,如果未能解决你的问题,请参考以下文章

[Javascript] Avoid Creating floats if they are not needed

GORM 基础 -- CRUD 接口

[FAQ] web3js, Error: Please pass numbers as strings or BN objects to avoid precision errors.

可选择将.Where()应用于gorm.DB

Tips on Java

使用gorm的postgres中的“$ 1”或附近的golang语法错误