gpt4 book ai didi

postgresql - 序列不存在时不存在 - Postgres/Spring Boot

转载 作者:行者123 更新时间:2023-11-29 13:19:02 26 4
gpt4 key购买 nike

我正在编写一个 Spring Boot 网络应用程序并使用 Postgres 数据库来保存我的数据。我使用 create table user (id bigserial primary key not null, name text not null; 在 Postgres 中创建了一个表,并通过查看模式识别了它的 sequence_name(在本例中,它是 user_id_seq)。然后,在我的 Spring Boot 中的 User 实体类中,我添加了以下内容:

@Entity
@Table(name = "user")
public class User implements Serializable {

@Id
@SequenceGenerator(name = "user_local_seq", sequenceName = "user_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_local_seq")
private Long id;
...

确保 sequenceName 与我之前看到的相匹配。现在,当我启动我的 spring boot 应用程序时,我能够成功启动它,但我在跟踪中收到以下“错误”:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : ERROR: sequence "user_id_seq" does not exist

我关闭了应用程序并再次启动它,这一次,我得到了:

main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop sequence user_id_seq
main] org.hibernate.tool.hbm2ddl.SchemaExport : ERROR: sequence "user_id_seq" does not exist

这是什么意思?我错过了什么吗?感谢任何帮助/见解。

最佳答案

这是洞察力。

ERROR: sequence "user_id_seq" does not exist

这意味着您的序列要么不存在于数据库中要么用户无权访问它。

解决方案:

  1. 通过命令\ds查询数据库中的user_id_seq
  2. 向特定用户授予序列访问权限。
    GRANT ALL ON ALL SEQUENCES IN SCHEMA schema_name TO user_name;

关于postgresql - 序列不存在时不存在 - Postgres/Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44962937/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com