The following code sample show be self-explanatory, I think.
package main
import (
"fmt"
"log"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
type User struct {
ID uint
Name string
}
type UserChanged struct {
ID uint
Name int
}
func (UserChanged) TableName() string {
return "users"
}
func main() {
db, _ := gorm.Open(sqlite.Open("gorm.db"), &gorm.Config{})
// auto-migrate initial table structure
if err := db.AutoMigrate(&User{}); err != nil {
log.Fatal(err)
}
// create a view depending on it
if err := db.Migrator().CreateView("user_views", gorm.ViewOption{Query: db.Raw("SELECT * FROM users")}); err != nil {
log.Fatal(err)
}
// auto-migrate to new schema
if err := db.AutoMigrate(&UserChanged{}); err != nil {
log.Fatal(err)
}
fmt.Println("Not gonna get here")
}
This fails with error:
2026/02/13 20:52:45 error in view user_views: no such table: main.users
[0.155ms] [rows:0] ALTER TABLE `users__temp` RENAME TO `users`
2026/02/13 20:52:45 error in view user_views: no such table: main.users
exit status 1
In my understanding, the auto migrator's logic of dropping and re-creating a column (with altered schema) should involve to drop and re-create all depending views as well.
The following code sample show be self-explanatory, I think.
This fails with error:
In my understanding, the auto migrator's logic of dropping and re-creating a column (with altered schema) should involve to drop and re-create all depending views as well.