In addition to exported fields, you don't need to import

_ "github.com/lib/pq"


just these

    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/postgres"






четверг, 29 ноября 2018 г., 21:04:06 UTC+3 пользователь Mohamed Yousif 
написал:
>
> Beside exporting issue, you need to commit these models into your 
> database. I use .Create(). 
>
> On Thu, 29 Nov 2018 at 5:47 PM, Robert Engels <ren...@ix.netcom.com 
> <javascript:>> wrote:
>
>> If gorm is like json marshalling the fields need to be exported, that is 
>> capitalized. 
>>
>> Just a thought. 
>>
>> On Nov 29, 2018, at 12:02 AM, mmbari...@gmail.com <javascript:> wrote:
>>
>> New to Go - please bear with me.
>>
>> I am trying to create a new row in my table, but the values are being 
>> saved as `Null`. Can anyone see the problem here?
>>
>> package main
>>
>> import (
>>    "fmt"
>>    "log"
>>
>>     "github.com/jinzhu/gorm"
>>    _ "github.com/jinzhu/gorm/dialects/postgres"
>>    _ "github.com/lib/pq"
>> )
>>
>> type contact struct {
>>    gorm.Model
>>    id    int    `gorm:"primary_key;not null;unique;AUTO_INCREMENT"`
>>    fname string `gorm:"type:TEXT"`
>>    lname string `gorm:"type:TEXT"`
>>    email string `gorm:"type:TEXT"`
>> }
>>
>> func main() {
>>    connStr := "user=postgres dbname=postgres sslmode=disable"
>>    db, err := gorm.Open("postgres", connStr)
>>
>>     if err != nil {
>>        log.Fatal(err)
>>    }
>>
>>     defer db.Close()
>>
>>     db.AutoMigrate(&contact{})
>>
>>     c := contact{
>>        fname: "bob",
>>        lname: "job",
>>        email: "b...@jb.com <javascript:>",
>>    }
>>
>>     fmt.Println(&c)
>>    db.Create(&c)
>>
>> }
>>
>> <Screen Shot 2018-11-29 at 1.01.55 AM.png>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> <Screen Shot 2018-11-29 at 1.01.55 AM.png>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to