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

Don't set NULL if timestamp column is Primary Key #2332

Merged
merged 2 commits into from
Apr 14, 2019
Merged

Don't set NULL if timestamp column is Primary Key #2332

merged 2 commits into from
Apr 14, 2019

Conversation

zaneli
Copy link
Member

@zaneli zaneli commented Mar 14, 2019

Make sure these boxes checked before submitting your pull request.

  • Do only one thing
  • No API-breaking changes
  • New code/logic commented & tested

For significant changes like big bug fixes, new features, please open an issue to make an agreement on an implementation design/plan first before starting it.

What did this pull request do?

type Time struct {
	Time time.Time `gorm:"primary_key"`
}

db.CreateTable(&Time{})
  • before
(/Users/zaneli/go/src/github.com/zaneli/gorm/main.go:737)
[2019-03-14 16:47:06]  Error 1171: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

(/Users/zaneli/go/src/github.com/zaneli/gorm/scope.go:1034)
[2019-03-14 16:47:06]  [0.97ms]  CREATE TABLE `times` (`time` timestamp NULL , PRIMARY KEY (`time`))
  • after
(/Users/zaneli/go/src/github.com/zaneli/gorm/scope.go:1034)
[2019-03-14 16:47:35]  [6.00ms]  CREATE TABLE `times` (`time` timestamp , PRIMARY KEY (`time`))

@zaneli
Copy link
Member Author

zaneli commented Mar 14, 2019

maybe since MySQL 5.7.3

https://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-3.html

Columns in a PRIMARY KEY must be NOT NULL, but if declared explicitly as NULL produced no error. Now an error occurs.

@zaneli
Copy link
Member Author

zaneli commented Apr 14, 2019

I fixed conflict for merge.

@jinzhu @emirb
Please take another look.

@jinzhu jinzhu merged commit 7bc3561 into go-gorm:master Apr 14, 2019
@zaneli zaneli deleted the mysql_time_pk branch April 14, 2019 13:13
blefevre pushed a commit to blefevre/gorm that referenced this pull request Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants