go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.95k stars 3.93k forks source link

[Bug] Migrator not recognizing data type change #4371

Closed sujit-baniya closed 3 years ago

sujit-baniya commented 3 years ago

Initial Migration has following struct

type ProviderRoute struct {
    *gorm.Model
    Test           int   `gorm:"test" json:"test" form:"test" query:"test"`
    Priority             int    `gorm:"priority" json:"priority" form:"priority" query:"priority"`
}

Then I changed the data type of Test to string and tried to migrate again. The migrator this time is not updating the data type

github-actions[bot] commented 3 years 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 2 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

s-takehana commented 3 years ago

Similar to #4308 . Maybe GORM can't do it.

https://gorm.io/docs/migration.html#Auto-Migration

It will change existing column’s type if its size, precision, nullable changed.

https://github.com/go-gorm/gorm/blob/a480bd85450d444d2526a309f2ecae07cac814c0/migrator/migrator.go#L371-L414

github-actions[bot] commented 3 years 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 2 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

yungsem commented 3 years ago

I meet the same problem. Can it be solved?

github-actions[bot] commented 3 years 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 2 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

sujit-baniya commented 3 years ago

It seems for reliable migrations, we can't use Gorm migrator.

github-actions[bot] commented 3 years 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 2 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