我启动了一个连接到MySQL数据库的Spring Boot项目。在我的application.properties中,我放入了spring.jpa.hibernate.ddl-auto = update,但是在我更新了实体中的表名之后,一个新的表被创建了,并且在我更新了property的列名之后,一个新的列被创建了。
## 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发布于 2018-08-19 01:32:23
spring.jpa.hibernate.ddl-auto = update请理解,update操作将尝试添加新的列、约束等,但永远不会删除以前可能存在于但不再作为对象模型的一部分的列或约束。
发布于 2022-02-06 13:58:12
然而,我也有同样的疑惑,就像上面写的注释一样,spring.jpa.hibernate.ddl-auto=update只检测更改并更新数据库上的更改,就好像它是一个新事物一样。
因此,如果您在本地运行,我建议您这样做
spring.jpa.hibernate.ddl-auto=create-drop。
但是这将删除所有记录,所以如果您真的想“更新”,那么手动更新这些列和表名。
https://stackoverflow.com/questions/51902166
复制相似问题