修改实体字段时,数据库中的 Spring Boot 表未更新 [英] Spring boot tables in database not updated when entity field is modified

查看:174
本文介绍了修改实体字段时,数据库中的 Spring Boot 表未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Spring boot 创建 API 时,我创建了一个实体 User,其中包含一些字段,例如 firstnamelastname、...

When using Spring boot to create an API, I've created an entity User with some fields like firstname, lastname, ...

我第一次启动应用程序时,在数据库中创建了包含所有字段的表.
然后我更新一个字段,向其中添加 @Column(nullable = false).
然后,当我再次运行该应用程序时,该字段不会使用我添加的新属性进行更新.

The first time I've launched the application, the table is created in the database with all the fields.
Then I update one field adding @Column(nullable = false) to it.
And then, when I run the application again the field is not updated with the new attribute I've added to it.

在我的 application.properties 中,我使用了这个参数:spring.jpa.hibernate.ddl-auto=update 但它没有更新任何东西,我不知道为什么

In my application.properties i use this param: spring.jpa.hibernate.ddl-auto=update but it's not updating anything i don't know why

推荐答案

确保列不能有 NULL 值.如果该列具有空值,则 SQL 查询未执行.您可以先删除该列,然后重新创建.

Ensures that a column cannot have NULL value. If the column have null value then SQL query is not executing. You can delete the column first then create it again.

这篇关于修改实体字段时,数据库中的 Spring Boot 表未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆