zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    菜根谭#308
    菜根谭#307
    菜根谭#306
    菜根谭#305
    菜根谭#304
    菜根谭#303
    菜根谭#302
    菜根谭#301
    菜根谭#300
    菜根谭#299
  • 原文地址:https://www.cnblogs.com/Jedimaster/p/8849013.html
Copyright © 2011-2022 走看看