GORM Playground Link

https://github.com/go-gorm/playground/pull/566

Description

对整数类型使用 not null 标签,会导致迁移代码时出现两次 NOT NULL 例如: user_id bigint unsigned NOT NULL NOT NULL 只会出现在 mysql 中, 测试了 gorm.io/driver/mysql v1.4.1 和 v1.4.6 版本都会这样,其他数据库没有问题

测试代码:

type Post struct {
    ID uint
    Title string `gorm:"notnull"`
    UserID uint `gorm:"notnull"`
    TestInt int `gorm:"notnull"`
    TestInt16 int16  `gorm:"notnull"`
}

func TestGORM(t *testing.T) {
    DB.Debug().AutoMigrate(new(Post))
}

输出:

CREATE TABLE posts (
  id BIGINT UNSIGNED AUTO_INCREMENT, 
  title LONGTEXT NOT NULL, 
  `user_id bigint unsigned NOT NULL NOT NULL`, 
  `test_int bigint NOT NULL NOT NULL`, 
  `test_int16 smallint NOT NULL NOT NULL`, 
  PRIMARY KEY (id)
);

Comment From: alresvor

应该是这个提交 https://github.com/go-gorm/mysql/commit/4a5168734eef0508992783ef0a190148a5aa9dcf 添加的