英文:
How to skip some of the entity from ddl update
问题
我有几个javax.persistence.Entity
,其中大部分是为当前模块创建的,所以保持
spring.jpa.hibernate.ddl-auto = update
由于某些表已经存在,我想知道如何跳过更新一些已经存在的实体的DDL。
另外,我可以接受应用在运行时失败,但出现损坏的表。
英文:
have several javax.persistence.Entity
most of them are created for the current module, so keeping
spring.jpa.hibernate.ddl-auto = update
Since some of the tables are already there. I was wondering how can I skip updating the DDL for a few of the already existing entities.
also, I am okay letting the application fail on runtime but have a corrupted table.
答案1
得分: 2
根据评论中的建议,这是一个使用迁移工具像fylway/liquibase会非常有帮助的情况。
https://www.baeldung.com/database-migrations-with-flyway
通过指定(如指南中所示)CREATE TABLE IF NOT EXISTS ...
,只有在表尚不存在时才会创建表,这正是您想要的。
英文:
Like advised in the comment it is a situation where a migration tool like fylway/liquibase would be most helpful.
https://www.baeldung.com/database-migrations-with-flyway
By specifying (like shown in the guide) CREATE TABLE IF NOT EXISTS ...
your tables will only be created if they don't exist already which is exactly what you wanted
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论