Skip to content
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

用tag指定数据库字段为int类型的字段默认值时,create函数生成的sql语句多了一列 #6247

Closed
DearZL opened this issue Apr 18, 2023 · 11 comments
Assignees
Labels

Comments

@DearZL
Copy link

DearZL commented Apr 18, 2023

GORM Playground Link

go-gorm/playground#1

Description

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Apr 18, 2023
@github-actions
Copy link

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.ioSearch Before Asking

@labulakalia
Copy link
Contributor

show your case!!!

@github-actions
Copy link

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.ioSearch Before Asking

@DearZL
Copy link
Author

DearZL commented Apr 23, 2023 via email

@github-actions
Copy link

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.ioSearch Before Asking

@DearZL
Copy link
Author

DearZL commented Apr 23, 2023

ErrorPicture+Code.zip

@github-actions
Copy link

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.ioSearch Before Asking

@philhuan
Copy link
Contributor

你的结构体

type File struct {
Id int json:"id" gorm:"default:2"
Filename string json:"filename"
Location string json:"location"
}

@philhuan
Copy link
Contributor

你试试加上 primarykey, 不加这个 gorm 不能识别这是一个主键

func TestDefault(t *testing.T) {
	type User struct {
		ID   uint `gorm:"primarykey,default:100"`
		Name string
		Age  uint
	}

	user := User{Name: "philhuan"}

	err := DB.Create(&user).Error
	assert.NoError(t, err)
	t.Log(user)
}
=== RUN   TestDefault

2023/05/15 23:46:40 /Users/philhuan/code/go/playground/main_test.go:109
[8.878ms] [rows:1] INSERT INTO `users` (`name`,`age`) VALUES ('philhuan',0)
    main_test.go:111: {6 philhuan 0}
--- PASS: TestDefault (0.01s)
PASS

@DearZL
Copy link
Author

DearZL commented May 15, 2023

type User struct {
ID uint gorm:"primarykey,default:100"
Name string
Age uint
}
为什么primarykey和default:100要用,隔开,不是分号吗

@github-actions
Copy link

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.ioSearch Before Asking

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants