Spring Boot不会在Postgres中创建表

时间:2018-07-11 14:32:56

标签: java postgresql spring-boot spring-data

我正在尝试基于实体生成模式表。但是不会创建表。怎么了?

实体示例:

@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

3 个答案:

答案 0 :(得分:4)

应该是:

spring.jpa.generate-ddl = true

在您的application.properties中。

或者您可以更改此行:

spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.ddl-auto=create

更多详细信息:Spring Database initialization

答案 1 :(得分:1)

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

答案 2 :(得分:0)

尝试添加此属性 spring.datasource.driverClassName=org.postgresql.Driver

并将 spring.jpa.hibernate.ddl-auto 从更新更改为创建