Gorm: Ignore flag not working on model struct?

Created on 1 May 2016  路  12Comments  路  Source: go-gorm/gorm

I have this model:

type User struct {
    gorm.Model

    // The Users username
    Username string `gorm:"size:255;unique;not null"`

    // The Users email address
    Email string `gorm:"size:255;unique;not null"`

    // The Users hashed password
    Password string `gorm:"size:255;not null"`

    // The Users password confirmation (only for forms)
    PasswordC string `gorm:"-"`

    // The Users FULL NAME (e.g. Burt Reynolds)
    Fullname string `gorm:"size:255; not null"`

    // The Users Karma level
    Karma int

    // Is the user banned?
    Banned bool
}

But PasswordC still shows up in my database using db.AutoMigrate(User{}) I thought gorm:"-" made it be ignored, I wanted to have a PasswordC field for using with Gorilla Schema

Most helpful comment

Please release a new version

All 12 comments

Are you using an old version?

I am using the most latest version, my above struct is still creating a PasswordC field in the database:

http://imgur.com/2VxLPLa

I just deleted gorm and did a fresh go get github.com/jinzhu/gorm and I deleted the users table but it still comes back with the passwordc field

package models

import (
    "log"

    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/postgres"
)

var DB *gorm.DB

func init() {
    db, err := gorm.Open("postgres", "user=postgres dbname=bdo_pug sslmode=disable")
    if err != nil {
        log.Println(err)
    }
    DB = db

    DB.AutoMigrate(&User{})
}

Seemed to fix it by adding sql:"-" to it but I thought that was the responsibility of the gorm:"-" flag

I don't know why this issue was so quick to close. It is clearly an issue that is still an issue, unless the documentation or the code needs to figure out which one is backwards

http://stackoverflow.com/questions/36963008/gorm-not-ignoring-field-with-gorm/36974118#36974118

Hi @Gacnt

Sorry for this, I made a mistake, as there are some misusage about tags before caused by not upgrade to latest version, I thought this is same issue.

Just fixed this, sorry.

I'm having the same problems using the most recent version of gorm.

type User struct {
  gorm.Model
  Email string `json:"email" gorm:"column:email"`
  /*
  ...
  */
  UserData map[string]interface{} `json:"data" sql:"-" gorm:"-"`

sql: Scan error on column index 9: unsupported driver -> Scan pair: []uint8 -> map[string]interface{}

I'm also having this issue.

I still have problem with this :/

Hi, @mehdy could you write a script and create a new issue to prove that?

Oh, I think I found the problem. I was using glide and it selected the stable version of gorm which was released almost a year ago!

have you considered releasing new versions?

Please release a new version

gorm: "-" still adds the column for me?

Was this page helpful?
0 / 5 - 0 ratings