Add tests for alter column type
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/lib/pq"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
. "gorm.io/gorm/utils/tests"
|
||||
)
|
||||
|
||||
func TestPostgresReturningIDWhichHasStringType(t *testing.T) {
|
||||
@@ -199,3 +200,18 @@ func TestPostgresOnConstraint(t *testing.T) {
|
||||
t.Errorf("expected 1 thing got more")
|
||||
}
|
||||
}
|
||||
|
||||
type CompanyNew struct {
|
||||
ID int
|
||||
Name int
|
||||
}
|
||||
|
||||
func TestAlterColumnDataType(t *testing.T) {
|
||||
DB.AutoMigrate(Company{})
|
||||
|
||||
if err := DB.Table("companies").Migrator().AlterColumn(CompanyNew{}, "name"); err != nil {
|
||||
t.Fatalf("failed to alter column from string to int, got error %v", err)
|
||||
}
|
||||
|
||||
DB.AutoMigrate(Company{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user