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

[BUG] - MySQL doesn’t treat null as a valid default for NOT NULL fields #35

Closed
cybereyes-sunny opened this issue Oct 28, 2024 · 3 comments · Fixed by #39
Closed

[BUG] - MySQL doesn’t treat null as a valid default for NOT NULL fields #35

cybereyes-sunny opened this issue Oct 28, 2024 · 3 comments · Fixed by #39
Assignees
Labels
bug Something isn't working

Comments

@cybereyes-sunny
Copy link

cybereyes-sunny commented Oct 28, 2024

Describe the bug

Update Worker and Status Fields in CronJobLock to Use Compatible Default Values

To Reproduce

Steps to reproduce the behavior:

follow the example and exec:

db.AutoMigrate(&gormlock.CronJobLock{})

Version

github.com/go-co-op/gocron-gorm-lock v1.0.0

Expected behavior

The Worker and Status fields in the CronJobLock struct currently have gorm:"not null;default:null". Setting null as a default for NOT NULL fields leads to migration errors in MySQL because MySQL doesn’t support null as a default for NOT NULL columns.

To make this compatible with MySQL and similar databases, these fields should be updated to use an empty string ('') as the default. This will allow migrations to run smoothly without encountering Invalid default value errors.

Additional context

2024/10/28 09:29:11 failed to migrate database: Error 1067 (42000): Invalid default value for 'worker'

Worker string `gorm:"not null;default:null"`

Status string `gorm:"not nullldefault:null"`

@cybereyes-sunny cybereyes-sunny added the bug Something isn't working label Oct 28, 2024
@cybereyes-sunny cybereyes-sunny changed the title [BUG] - Please add descriptive title [BUG] - MySQL doesn’t treat null as a valid default for NOT NULL fields Oct 28, 2024
@manuelarte manuelarte self-assigned this Nov 15, 2024
@manuelarte manuelarte linked a pull request Nov 15, 2024 that will close this issue
2 tasks
@manuelarte
Copy link
Collaborator

@cybereyes-sunny I created a PR, once it's merged the issue should be solved

@cybereyes-sunny
Copy link
Author

Thanks for your work!

@manuelarte
Copy link
Collaborator

Version v1.0.1 with the fix has been released: https://github.com/go-co-op/gocron-gorm-lock/releases/tag/v1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants