Skip to content

Commit

Permalink
Set AutoIncrement to false with tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Feb 10, 2018
1 parent 97495a5 commit 2c68f69
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 3 additions & 6 deletions dialect_common.go
Expand Up @@ -39,13 +39,10 @@ func (commonDialect) Quote(key string) string {
}

func (s *commonDialect) fieldCanAutoIncrement(field *StructField) bool {
// add a new tag "NOT_AUTO_INCREMENT"
_, not := field.TagSettings["NOT_AUTO_INCREMENT"]
if not {
return false
if value, ok := field.TagSettings["AUTO_INCREMENT"]; ok {
return value != "FALSE"
}
_, ok := field.TagSettings["AUTO_INCREMENT"]
return ok || field.IsPrimaryKey
return field.IsPrimaryKey
}

func (s *commonDialect) DataTypeOf(field *StructField) string {
Expand Down
4 changes: 3 additions & 1 deletion main_test.go
Expand Up @@ -72,8 +72,10 @@ func OpenTestConnection() (db *gorm.DB, err error) {

// db.SetLogger(Logger{log.New(os.Stdout, "\r\n", 0)})
// db.SetLogger(log.New(os.Stdout, "\r\n", 0))
if os.Getenv("DEBUG") == "true" {
if debug := os.Getenv("DEBUG"); debug == "true" {
db.LogMode(true)
} else if debug == "false" {
db.LogMode(false)
}

db.DB().SetMaxIdleConns(10)
Expand Down
2 changes: 1 addition & 1 deletion test_all.sh
@@ -1,5 +1,5 @@
dialects=("postgres" "mysql" "mssql" "sqlite")

for dialect in "${dialects[@]}" ; do
GORM_DIALECT=${dialect} go test
DEBUG=false GORM_DIALECT=${dialect} go test
done

0 comments on commit 2c68f69

Please sign in to comment.