postgresql Sping Boot 不会在Postgres中创建表

twh00eeo  于 2023-03-08  发布在  PostgreSQL
关注(0)|答案(4)|浏览(174)

我正在尝试基于实体生成架构表。但是没有创建表。出了什么问题?
实体示例:

@Entity
@NoArgsConstructor
@Getter @Setter
public class User {
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long id;

    public String username;
    public String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User(String username) {
        this(username, username + "pass");
    }
}

application.properties

spring.datasource.url=jdbc:postgresql://localhost:5432/dbtest
spring.datasource.username=vssekorin
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update

依赖关系:

compile('org.springframework.boot:spring-boot-starter-data-jpa')
runtime('com.h2database:h2')
compile('org.telegram:telegrambots:3.6.1')
runtime('org.postgresql:postgresql')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')

警告:GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement

qjp7pelc

qjp7pelc1#

它应该是:

spring.jpa.generate-ddl = true

在你的application.properties里。
或者您可以更改此行:

spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.ddl-auto=create

更多详情:Spring Database initialization

cgyqldqp

cgyqldqp2#

只需将spring.jpa.hibernate.ddl-autoupdate更改为create

5gfr0r5j

5gfr0r5j3#

尝试添加此属性spring.datasource.driverClassName=org.postgresql.Driver
并将spring.jpa.hibernate.ddl-auto从更新更改为创建

hi3rlvi2

hi3rlvi24#

实体(name=“Users”)postgresql无法创建名为user和

spring.jpa.hibernate.ddl-auto=create

相关问题