java - Spring Boot doesn't create tables in Postgres
问题描述
I am trying to generate schema tables based on entities. But tables are not created. What's wrong?
Entity example:
@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
Dependencies:
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')
Warning: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
解决方案
它应该是:
spring.jpa.generate-ddl = true
在你的application.properties
.
或者您可以更改此行:
spring.jpa.hibernate.ddl-auto=update
在
spring.jpa.hibernate.ddl-auto=create
更多细节:Spring 数据库初始化
推荐阅读
- python - 是否有 Python 模块可以让我创建像 CMD 这样的命令行界面?
- vb.net - 如何在 VB.Net 中定位内存地址?
- html - 选择后的角度变化选择类
- mongodb - 如何在 MongoDB 的一个查询中从多个集合中删除文档?
- java - 无法在 XAMPP(Windows)上运行 tomcat
- kafkajs - 如何使用 kafkajs-avro 确定通用消息的记录类型
- html - 通过 CSS 更改 html 中占位符的文本
- python - 删除pandas中特定列中n个最小值的行
- mysql - 有没有一种方法可以通过命令行在 MySQL 中永久设置我的 root 密码,而无需每次都使用“mysql -u root -p”?
- c# - EmguCV C# 轮廓检测