@UniqueConstraint 需要在 MariaDB 中更改 table 如果 table 之前已经存在且没有约束?
@UniqueConstraint requires alter table in MariaDB if table already existed before with no constraints?
如果我重复这个问题,我深表歉意,但我没有找到类似的。
我在已经存在的 table 上添加了唯一约束。我们使用 MariaDB。
我用过注解:
@Table(uniqueConstraints={@UniqueConstraint(name="autonomy_name_energyType", columnNames={"autonomy","name","energyType"})})
单元测试通过,但在数据库中我仍然可以创建重复项。
我也需要 ALTER table 吗?通过检查 table 我可以看到没有添加任何约束。
谢谢
如这些 SO 帖子中所述:
Unique constraint not created in JPA
@Column(unique=true) does not seem to work
需要显式更改 table 查询才能使您的约束在数据库级别生效。
作为额外信息,如果 table 是通过 JPA 重新创建的,它会起作用。看 :
Add a unique constraint over muliple reference columns
如果我重复这个问题,我深表歉意,但我没有找到类似的。
我在已经存在的 table 上添加了唯一约束。我们使用 MariaDB。
我用过注解:
@Table(uniqueConstraints={@UniqueConstraint(name="autonomy_name_energyType", columnNames={"autonomy","name","energyType"})})
单元测试通过,但在数据库中我仍然可以创建重复项。
我也需要 ALTER table 吗?通过检查 table 我可以看到没有添加任何约束。
谢谢
如这些 SO 帖子中所述:
Unique constraint not created in JPA
@Column(unique=true) does not seem to work
需要显式更改 table 查询才能使您的约束在数据库级别生效。
作为额外信息,如果 table 是通过 JPA 重新创建的,它会起作用。看 : Add a unique constraint over muliple reference columns