如果我将这样的列添加到现有实体,hibernate 将无法添加该列,因为存在没有值的现有行:
@Column(name = "width", nullable = false)
private int width;
失败并出现此错误:
2015-11-14 20:33:41.163 ERROR 9068 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000388: Unsuccessful: alter table texture add column width int4 not null
2015-11-14 20:33:41.163 ERROR 9068 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaUpdate : FEHLER: Spalte „width“ enthält NULL-Werte
我不想在我的数据库列定义中使用默认值。
最佳答案
您必须使用现有数据更改表,因此如果列不可为空且未指定默认值,则无法将列添加到现有行。
所以我认为你需要允许为空或指定一个默认值,你别无选择......
关于java - 如何使用 'ddl-auto=update' 和 'nullable=false' 添加新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33712538/