Jav*_*ava 1 java postgresql spring h2
我有一个在 H2 DB 上运行良好的 Spring Boot 应用程序。如果我想切换到 postgresQL,我会收到错误消息。
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
Run Code Online (Sandbox Code Playgroud)
错误:
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
Run Code Online (Sandbox Code Playgroud)
我认为这是因为user是 PostrgeSQL 中的保留字。
为了创建具有这样名称的表,请尝试引用它(即create table "user"...)
如果您想要不同数据库之间的互操作性,将所有对象的名称括在“ANSI 引号”中通常是一个好主意。
| 归档时间: |
|
| 查看次数: |
999 次 |
| 最近记录: |