The AutoMigrate method on already existing entities does not deal with unique index and the nullable column accurately.
package main
import (
spannergorm "github.com/googleapis/go-gorm-spanner"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type Apple struct {
AppleID string `gorm:"primaryKey"`
Name string `gorm:"not null;index:idx_name_email,unique"`
Email string `gorm:"not null;index:idx_name_email,unique"`
Age int
}
func main() {
// Replace with your actual Cloud Spanner project, instance, and database
dsn := "projects/your-project-id/instances/your-instance/databases/your-db"
db, err := gorm.Open(spannergorm.New(spannergorm.Config{
DriverName: "spanner",
DSN: dsn,
}), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
})
if err != nil {
panic("failed to connect database")
}
// AutoMigrate will create the table with the unique indexes
db.AutoMigrate(&Apple{})
}
Please refer to the following error:
rpc error: code = NotFound desc = uni_apples_name is not a constraint in apples
type Admin struct {
Id int64 `gorm:"column:id;primarykey;not null;comment:自增ID"`
LastLoginTime *time.Time `gorm:"column:last_login_time;null;default:null`
}
Please refer to the following error:
ALTER TABLE `user_admin` ALTER COLUMN `last_login_time` TIMESTAMP DEFAULT (null)
// Add this column again, it is not expected behavior
Environment details
- Programming language: Golang
- OS: MacBook
- Language runtime version: 1.23
- Package version: 1.4.0
Steps to reproduce
- Execute the sample code;
- Run it again;
- Change the sample code to use nullable column, and test it again
Thanks!
The AutoMigrate method on already existing entities does not deal with unique index and the nullable column accurately.
Please refer to the following error:
Please refer to the following error:
Environment details
Steps to reproduce
Thanks!