Spring Boot - JPA Hibernate 不会自动创建表?

Bla*_*y-Z 4 java postgresql hibernate jpa spring-boot

我的文件中有这段代码application.properties

# Spring DataSource
spring.datasource.driverClassName=org.postgresql.Driver
spring.sql.init.mode=always
spring.sql.init.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/dbname
spring.datasource.username=postgres
spring.datasource.password=root

# JPA-Hibernate
spring.jpa.generate-ddl=true
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=create

# /sf/ask/3073358361/
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true

# Optimization for POSTGRES queries
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我spring.jpa.hibernate.ddl-auto=create添加了该行,但 JPA 仍未创建表。我必须手动创建它们才能编译项目。怎么了?

小智 5

您可以使用spring.jpa.hibernate.ddl-auto=update并检查您是否在实体类上使用 @Table(name="table_name") top 。这可能有帮助