java - application.properties 中 spring.jpa.hibernate.ddl-auto=update 的问题
问题描述
我的文件有问题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
- 这将在应用程序终止时破坏您的数据库模式。
编辑:
您无法在不破坏数据的情况下更新数据库架构。想象一下,您正在更改某个字段的数据类型并且已经有数据。数据库不知道如何转换现有数据。
推荐阅读
- javascript - next.js 构建时间很慢。我怎样才能让它们更快?
- python - How do you separate a column with words not separated at all. The data loaded from pd.read_table?
- flutter - 创建适用于 android 和 ios 的自适应 ui 的最佳方法是什么
- git - 一个分支的变化反映在所有分支中
- spartacus-storefront - 我想将页面显示为类别页面,因为所有页面都作为内容页面加载
- c# - 如何在asp中具有不同参数的另一个事件处理程序中调用事件处理程序?
- java - 如何用大括号分割字符串?
- node.js - 是否有一种“标准”方式来构建 API 的 HTTP GET 请求?
- arrays - Wordpress / PODS - 将关系字段中的数组项作为单个项回显
- postgresql - docker连接上带有postgres和redis的Nestjs被拒绝