簡體   English   中英

"Hibernate-Spring boot : spring.jpa.hibernate.ddl-auto=update 更新實體后重新創建表和列"

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM