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
AutoMigrate will not update changed default
value for primary keys
#6963
Comments
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 |
Yes, this is intentional, migrating primary keys is a dangerous practice. |
would it be possible to add a clause or some other flag to allow migrating the primary key? Having a protective default to not do so makes sense, but there are cases where it is desired, and where the user has their own protection in place/is willing to take the risk. |
You can use |
GORM Playground Link
go-gorm/playground#716
Description
I recently changed all of my tables to use a default for the UUID primary key so that if I forget to set a value, the default takes over and generates a UUID for me. Specifically, this is for the primary keys (I have tested my example with non primary keys and changing/adding a default works fine). I have tested this example with postgres 15.
After checking the database table data (via pgadmin), the
default
of UUID has not been changed, and is still empty.From my perusal of the migrator code, this lack of change appears to be the case due to the
!field.PrimaryKey
check here, which makes it appear intentional, but I was not able to find any documentation of this limitation, or reasoning as to why this limit exists. Its even stranger as you can set the default for a primary key on table creation.Is it possible this check was made to prevent setting
default:someConst
for the primary key?The text was updated successfully, but these errors were encountered: