Open y-okuno opened 2 weeks ago
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.io ✨ Search Before Asking ✨
My team just experienced the same problem.
The constraint is not present because GORM is calculating the name wrong. I'm also wondering if the dropping of the constraint shouldn't also have IF EXISTS
as that would have stopped the migration from failing.
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.io ✨ Search Before Asking ✨
Description:
I encountered an issue with GORM's
AutoMigrate
function when upgrading to the latest versions.Successful migration with:
gorm.io/driver/postgres v1.4.8
gorm.io/gorm v1.25.5
Failed migration with:
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
In the latest version, it seems that the index name specified in the model is not being respected. The
AutoMigrate
function creates an incorrect index name which leads to a migration failure.Steps to Reproduce
Use the following versions:
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.10
Define the model as follows:
Create the table in PostgreSQL with the following SQL:
Execute AutoMigrate method with the above model.
Also tried with the following model definition, but the result was the same:
Expected Behavior
The migration should succeed without errors.
Actual Behavior
The migration fails with the following error:
It appears that AutoMigrate is attempting to create a constraint named
uni_masters_ipv4_prefix
instead of respecting the specifiedidx_masters_ipv4_prefix
.Environment
Additional Context
This issue does not occur with the following versions:
It seems that the index name specified in the struct tag is not being applied correctly in the latest version.
Thank you for your attention to this issue. Please let me know if you need any further information or assistance in reproducing the issue.