【发布时间】:2019-08-28 08:26:54
【问题描述】:
我对文件application.properties 有疑问,在这一行:
spring.jpa.hibernate.ddl-auto=update
当我从我的实体中删除一些属性时,这些属性仍然保留在数据库中。
这是 application.properties 的副本:
spring.jpa.generate-ddl=true
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect =
org.hibernate.dialect.MySQL5Dialect
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/taskmanagement
spring.datasource.username = root
spring.datasource.password =
server.port=89
spring.data.rest.default-media-type= application/json
我该如何解决这个问题?
【问题讨论】:
-
问题不在于属性
-
你不能。
update只会添加新的列和约束。它不会删除列、约束等。此外,您真的不应该将update或create用于任何其他测试,对于真正的数据库管理,您希望使用 Flyway 或 LiquiBase 之类的东西。 -
Hibernate AFAIK 无法实现可靠的数据库更新。 Flyway 或 Liquidbase 等工具专为数据库迁移而设计
标签: java spring database spring-data-jpa spring-data