New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto increment doesn't work #2190

Closed
onecaffeine opened this Issue Nov 23, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@onecaffeine
Copy link

onecaffeine commented Nov 23, 2018

Your issue may already be reported! Please search on the issue track before creating one.

What version of Go are you using (go version)?

go1.11.1

Which database and its version are you using?

mysql 8.0.13

package main

import (
	"fmt"
)

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

type TParkRecord struct {
	ID       uint `gorm:"type:bigint(20) unsigned;not null;auto_increment;primary_key"`
	ParkCode int  `gorm:"type:bigint(10) unsigned;not null;default:'0'"`
}

func (t TParkRecord) TableName() string {
	return "t_park_record"
}

func main() {
	db, err := gorm.Open("mysql", "user:password@/dbname?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		fmt.Println(err)
	}
	defer db.Close()

	db.LogMode(true)

	db.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE = utf8_bin").AutoMigrate(&TParkRecord{})
}

when i run this code,i found auto increment doesn't work.

image

@onecaffeine

This comment has been minimized.

Copy link
Author

onecaffeine commented Nov 25, 2018

@jinzhu
please tell me what should i do?thx

@baocaixiong

This comment has been minimized.

Copy link

baocaixiong commented Dec 4, 2018

@onecaffeine
请像这样定义字段

ID uint64 `gorm:"type:bigint(20) unsigned auto_increment;not null;primary_key"`
@dengguojie

This comment has been minimized.

Copy link

dengguojie commented Dec 15, 2018

@baocaixiong
it works!!
why AUTO_INCREMENT is special for bigint ??

@inliquid

This comment has been minimized.

Copy link

inliquid commented Dec 15, 2018

Seems this comment clarifies:
#201 (comment)

@dengguojie

This comment has been minimized.

Copy link

dengguojie commented Dec 17, 2018

@inliquid Thanks. I get it.

@onecaffeine

This comment has been minimized.

Copy link
Author

onecaffeine commented Dec 20, 2018

@baocaixiong thx,it works!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment