我启动了连接到 MySQL 数据库的 Spring Boot 项目。在我的 application.properties 中,我放置了 spring.jpa.hibernate.ddl-auto = update ,但在更新实体中的表名称后,仍然创建了一个新表,在我更新属性的列名称后,将创建一个新列。
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url = jdbc:mysql://localhost:3306/d-gdd?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false
spring.datasource.username = root
spring.datasource.password =
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
最佳答案
spring.jpa.hibernate.ddl-auto = update
请理解,更新操作将尝试添加新列、约束等,但绝不会删除以前可能存在的列或约束,但不再像以前那样对象模型的一部分。
关于java - Hibernate-Spring boot : spring. jpa.hibernate.ddl-auto=update 更新实体后重新创建表和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51902166/