【发布时间】:2021-06-26 13:16:07
【问题描述】:
表结构messages-
id - Integer - NotNull - Primary Key
message - text - NotNull
当我尝试使用插入时
INSERT INTO messages(message) VALUES ('abc');
它给出了以下错误-
ERROR: null value in column "id" of relation "messages" violates not-null constraint
DETAIL: Failing row contains (null, abc).
SQL state: 23502
提前致谢!
【问题讨论】:
-
修改你的表,使 id 自动递增
-
@Strawberry 这正是我想知道的,关于如何在 Postgres 中做到这一点。
-
添加您的实体类..确保您已使用 @Id 注释的字段和定义的生成类型 stretegy。
-
使用数据类型
serial而不是整数。
标签: sql postgresql spring-boot