简体   繁体   中英

Hibernate-Spring boot : spring.jpa.hibernate.ddl-auto=update recreates tables and columns after update the entity

I started Spring Boot project connected to MySQL database. In my application.properties I put spring.jpa.hibernate.ddl-auto = update but still after I update the table name in the entity, a new Table is created, and after I update the column name of property a new column is created.

## 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

请理解, 更新操作将尝试添加新的列,约束等,但绝不会删除以前可能已存在但不再作为对象模型一部分的列或约束

I have had the same wondering, however, just like the comment written above, spring.jpa.hibernate.ddl-auto=update<\/code> only detects the changes and updates those changes on db as if it's a new thing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM