Go Version: 1.20 Gorm Version: gorm.io/gorm v1.25.2 Driver: gorm.io/driver/postgres v1.5.2

I have the following code.

type User struct {
    gorm.Model
    FullName string `json:"fullname"`
    Email    string `json:"email"`
    Password string `json:"password"`
}

type PostgresStore struct {
    db *gorm.DB
}

func NewPostgresStore(dsn string) (*PostgresStore, error) {
    db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
    if err != nil {
        return nil, err
    }

    db.AutoMigrate(User{})

    return &PostgresStore{
        db: db,
    }, nil
}

func (s *PostgresStore) CreateUser(u *User) error {
    user := new(User)
    if res := s.db.Where("email = ? AND full_name = ?", u.Email, u.FullName).First(user); res.RowsAffected > 0 {
        return errors.New("Record already exists")
    }
    if res := s.db.Create(u); res.Error != nil {
        return res.Error
    }
    return nil
}

func (s *PostgresStore) FindUser(id int) (*User, error) {
    user := new(User)
    if err := s.db.Where("id = ?", id).First(user).Error; err != nil {
        return nil, err
    }

    return user, nil
}

When creating new entry, the library gets another column fullName from nowhere and causes the next error:

ERROR: null value in column "fullName" of relation "users" violates not-null constraint (SQLSTATE 23502)
[1.732ms] [rows:0] INSERT INTO "users" ("created_at","updated_at","deleted_at","full_name","email","password") VALUES ('2023-08-07 13:11:41.535','2023-08-07 13:11:41.535',NULL,'yuser','hello@mail.s','123') RETURNING "id"

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: intervinn

That is completely my issue. I did not notice that AutoMigrate() does not delete any columns.