1 回答
TA贡献1815条经验 获得超10个赞
将代码重写为这个,并始终记住在Gorm中我们需要将模型字段大写
package main
import (
"fmt"
_ "github.com/jinzhu/gorm/dialects/postgres"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type Books struct {
gorm.Model
ID uint
Title string
Author string
Description string
Display_Picture byte
}
func main() {
dsn := //successful create connection string
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
// fmt.Println(err)
panic(err)
}
b := Books{}
db.AutoMigrate(&b)
data := Books{
title: "Invisible Cities",
author: "Italio Calvino",
description: "This book shows you the power of prose. It's a beautiful read which will make you feel like you're floating on a cloud.",
}
db.Create(&data)
fmt.Println(data)
}
- 1 回答
- 0 关注
- 75 浏览
添加回答
举报