【问题标题】:Switching from H2 to PostgreSQL with spring boot使用 Spring Boot 从 H2 切换到 PostgreSQL
【发布时间】:2020-08-19 03:35:49
【问题描述】:

我有一个 Spring Boot 应用程序在 H2 DB 上运行良好。如果我想切换到 postgresQL,我会收到错误。

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres

错误:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "drop table if exists 
user cascade" via JDBC Statement
...
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
...
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table user (id int8 not null, active int4 not null, first_name varchar(255), last_name varchar(255), password varchar(255), role varchar(255), username varchar(255), primary key (id))" via JDBC Statement

【问题讨论】:

    标签: java spring postgresql h2


    【解决方案1】:

    我认为这是因为user 是 PostrgeSQL 中的保留字。

    为了创建一个具有该名称的表,请尝试引用它(即create table "user"...)

    如果您想要不同数据库之间的互操作性,将所有对象的名称包含在“ANSI 引号”中通常是一个好主意。

    【讨论】:

    • 谢谢我只需要像@Table(name="users")这样重命名表格
    猜你喜欢
    • 1970-01-01
    • 2020-04-27
    • 2018-10-19
    • 2019-09-06
    • 2019-06-12
    • 2017-01-16
    • 2022-12-12
    • 1970-01-01
    • 2020-11-06
    相关资源
    最近更新 更多