我有一张用户表。我想编写一个使用 id 获取数据的 API。我不断收到以下错误。请注意,数据库已满

我有一张用户表。我想编写一个使用 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)


慕森王
浏览 78回答 1
1回答

人到中年有点甜

您没有设置包级dbvar,因为您使用:=.如果出现错误,请退出mainfunc,这样您就不会继续使用 nil db。var db *gorm.DBfunc main() {    var err error    db, err = gorm.Open()    if err != nil {        log.Fatalf("unable to connect to database: %s", err.Error())    }}
打开App,查看更多内容
随时随地看视频慕课网APP