The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
Outliver0

[GO] gorm 连接 postgresql 如何指定 schemas

  •  
  •   Outliver0 · Jun 25, 2021 · 1924 views
    This topic created in 1809 days ago, the information mentioned may be changed or developed.

    dsn := "host=localhost user=" + user + " password=" + password + " dbname=" + dbName + " port=5432 sslmode=disable TimeZone=Asia/Shanghai"

    db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{ NamingStrategy: schema.NamingStrategy{ TablePrefix: tablePrefix, SingularTable: true, }, })

    使用的是 gorm v2,根据官方文档写的 dsn 我使用 db.AutoMigrate()迁移过后,迁移到了默认的 public 上面了

    还有个问题 gorm v2 中 BeforeCreate 怎么提前设置字段的值,感谢

    2 replies    2021-06-25 17:57:36 +08:00
    imherer
        1
    imherer  
       Jun 25, 2021
    我以前也问过类似的问题
    /t/704872
    Outliver0
        2
    Outliver0  
    OP
       Jun 25, 2021
    @imherer 迁移的时候怎么设置呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   959 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 21:54 · PVG 05:54 · LAX 14:54 · JFK 17:54
    ♥ Do have faith in what you're doing.