![](/img/trans.png)
[英]spring.jpa.hibernate.ddl-auto=update not working in spring boot
[英]Hibernate-Spring boot : spring.jpa.hibernate.ddl-auto=update recreates tables and columns after update the entity
我启动了连接到 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
请理解, 更新操作将尝试添加新的列,约束等,但绝不会删除以前可能已存在但不再作为对象模型一部分的列或约束 。
然而,我也有同样的疑惑,就像上面写的评论一样,
spring.jpa.hibernate.ddl-auto=update<\/code>只检测更改并更新 db 上的这些更改,就好像它是一个新事物一样。
因此,如果您在本地运行,我建议您这样做
spring.jpa.hibernate.ddl-auto=create-drop<\/code> 。
但这会删除所有记录,所以如果你真的想“更新”,那就手动更新那些列名和表名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.