我有一张用户表。我想编写一个使用 id 获取数据的 API。我不断收到以下错误。请注意,数据库已经满了。我想创建一个 get api,在其中传递 id 并获取该行作为结果。我尝试了一些方法,但我不断收到此错误。数据库架构-deadpool=# \d user_data Table "public.user_data" Column | Type | Collation | Nullable | Default--------------------+--------------------------+-----------+----------+--------------------------------------- id | integer | | not null | nextval('user_data_id_seq'::regclass) created_at | timestamp with time zone | | | updated_at | timestamp with time zone | | | deleted_at | timestamp with time zone | | | name | text | | | age | text | | | gender | text | | | party_code | text | | | criminal_cases | text | | | number_of_cases | text | | | serious_ipc_counts | text | | | ipc_details | text | | | education_level | text | | | movable_assets | text | | | immovable_assets | text | | | total_assets | text | | | total_liabilities | text | | | pan_given | text | | | election | text | | | constituency | text | | |Indexes: "user_data_pkey" PRIMARY KEY, btree (id) "idx_user_data_deleted_at" btree (deleted_at)
1 回答
人到中年有点甜
TA贡献1895条经验 获得超7个赞
您没有设置包级dbvar,因为您使用:=.
如果出现错误,请退出mainfunc,这样您就不会继续使用 nil db。
var db *gorm.DB
func main() {
var err error
db, err = gorm.Open()
if err != nil {
log.Fatalf("unable to connect to database: %s", err.Error())
}
}
- 1 回答
- 0 关注
- 106 浏览
添加回答
举报
0/150
提交
取消