![](/img/trans.png)
[英]spring.jpa.hibernate.ddl-auto=update not working in spring boot
[英]Problem with spring.jpa.hibernate.ddl-auto=update in application.properties
我的文件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
我怎么解决这个问题?
如果要基于对象映射重新创建数据库模式,只需使用:
spring.jpa.hibernate.ddl-auto=create
但是请记住,这会破坏您保存在数据库中的数据。
其他选项是使用create-drop
- 这将在应用程序终止时破坏您的数据库架构。
编辑:
您无法在不破坏数据的情况下更新数据库架构。 想象一下,您正在更改某个字段的数据类型并且已经有了数据。 数据库不知道如何转换现有数据。
属性spring.jpa.hibernate.ddl-auto
的update
值仅尝试添加新列和约束。 它不会从表中删除现有列。 尝试使用create
或create-drop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.