【问题标题】:Spring Boot doesn't create tables in PostgresSpring Boot 不在 Postgres 中创建表
【发布时间】:2018-12-19 15:42:21
【问题描述】:

我正在尝试基于实体生成架构表。但是没有创建表。怎么了?

实体示例:

@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

【问题讨论】:

  • 您能否显示此“GenerationTarget 遇到异常接受命令:通过 JDBC 语句执行 DDL 时出错”的完整日志

标签: java postgresql spring-boot spring-data


【解决方案1】:

应该是:

spring.jpa.generate-ddl = true

在你的application.properties

或者你可以改变这一行:

spring.jpa.hibernate.ddl-auto=update

spring.jpa.hibernate.ddl-auto=create

更多详情:Spring Database initialization

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 嗨@Aziz - 欢迎来到 Stack Overflow。在提供被 OP(原始帖子)作者接受的答案后 2.5 年以上,您的答案似乎没有添加任何新内容,或者您​​认为有,那么请编辑接受的答案以添加您的新见解。
      猜你喜欢
      • 2016-10-29
      • 2020-07-14
      • 1970-01-01
      • 2019-06-12
      • 2019-10-19
      • 2021-08-12
      • 2019-04-06
      • 2020-10-02
      • 2021-08-13
      相关资源
      最近更新 更多