go-gorm / playground

GORM Playground (Please Create PR for this project to report issues)
MIT License
89 stars 678 forks source link

AutoMigrate recreates table with composite unique index even if the m… #660

Open tyr0chen opened 10 months ago

tyr0chen commented 10 months ago

Explain your user case and expected results

In my use case, in sqlite driver, I have a model Gateway with a composite unique index defined on the fields IP and UIN. I expect that when running AutoMigrate, the table should only be recreated if there are changes to the model structure. However, I observed that the table is recreated every time AutoMigrate is called, even when the model has not changed.

Expected results:

When using a composite unique index, the table should not be recreated during AutoMigrate if the model structure has not changed. The unique attribute should be properly set for fields within a composite unique index, without affecting the behavior of AutoMigrate. After modifying the condition in the sqlite-driver code as mentioned in the original issue description, the behavior is as expected and the table is not recreated during AutoMigrate when the model has not changed.