Spring boot ddl自动生成器

gor*_*ill 31 java spring hibernate spring-boot

我正在使用spring boot spring.jpa.hibernate.ddl-auto=create,但是当应用程序重新启动时,所有表都会丢弃并再次创建.有没有办法避免现有表的重新创建?

sud*_*dar 64

弹簧启动中使用的选项列表是

  • validate:验证模式,不对数据库进行任何更改.
  • 更新:更新架构.
  • create:创建架构,销毁以前的数据.
  • create-drop:在会话结束时删除模式
  • none:是所有其他情况.

因此,为了避免数据丢失,您可以使用更新


sam*_*wis 48

spring.jpa.hibernate.ddl-auto=update
Run Code Online (Sandbox Code Playgroud)

hibernate.ddl-auto不应该在生产中使用.

  • @IllSc 这里有很多讨论:http://stackoverflow.com/questions/221379/hibernate-hbm2ddl-auto-update-in-product (2认同)