简体   繁体   中英

Switching from H2 to PostgreSQL with spring boot

I have a spring boot application working fine on a H2 DB. If I want to switch to postgresQL I get errors.

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

Errors:

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

I think this is because user is a reserved word in PostrgeSQL.

In order to create a table with such name, try quote it (that is, create table "user" ...)

Enclosing all the objects' names in 'ANSI quotes' is generally a good idea if you want an interoperability between different databases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM