I started using gorm + postresSQL - I do it stupidly according to the instructions, but it gives errors

type MyList struct { Id uint64 Name string IsTrue bool } 

hooked up

 "github.com/jinzhu/gorm" _ "github.com/lib/pq" db, err := gorm.Open("postgres", "user=Roman password=Roman dbname=DB1 sslmode=disable") if err != nil { log.Fatalf("error: %v\n", err) } db.DB() todo := MyList{Id:8888, Name: "Новое имя", IsTrue:false} var me MyList db.Where("Name = ?", "Новое имя").First(&me) fmt.Println(me) db.Create(&todo) db.NewRecord(todo) 

----- he swore

[35m (pq: the relation "my_lists" does not exist) [0m [33m [2016-02-01 18:58:50] [0m [31; 1m [0m

[35m (pq: the relation "my_lists" does not exist) [0m [33m [2016-02-01 18:58:50] [0m [31; 1m [0m

And does someone know how to get the ID of the inserted row through gorm? or should I immediately store the aydishnik in a +1 variable and insert this variable? (usually as it were, I would recognize "INSERT INTO test(value) VALUES($1) RETURNING id" ), but I don’t understand very well in the gorm.

  • The first decided. The table was otherwise called. Created db.CreateTable (& MyList {}) - Rakzin Roman

1 answer 1

 todo := MyList{Name: "Новое имя 2", IsTrue:false} db.Create(&todo) fmt.Println(todo.Id)