29 lines
577 B
Go
29 lines
577 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gorm.io/driver/sqlite"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// // User 模型
|
|
//
|
|
// type User struct {
|
|
// ID uint `gorm:"primaryKey"`
|
|
// Name string `gorm:"size:100;not null"`
|
|
// Email string `gorm:"size:100;unique;not null"`
|
|
// Age int `gorm:"default:0"`
|
|
// Active bool `gorm:"default:true"`
|
|
// CreatedAt time.Time
|
|
// UpdatedAt time.Time
|
|
// }
|
|
func main() {
|
|
db, _ := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
|
|
|
|
// 自动迁移(创建表)
|
|
db.AutoMigrate(&User{})
|
|
|
|
fmt.Println("Table created successfully!")
|
|
}
|