[英]Deletions with Spring data/Hibernate: ORA-01407: Cannot update to Null
我正在嘗試使用CRUD存儲庫中的deleteAll()
方法從數據庫中刪除特定表中的行。
這樣做時,我得到與我的DOG表有關的錯誤,行DOG_OWNER:
ORA-01407: Cannot update DOG_OWNER to Null
修復程序是僅刪除該行上的not-null constraint
,還是有其他解決方法?
在簡化的情況下, FOREIGN KEY
不可為ON DELETE SET NULL
,並且使用ON DELETE SET NULL
進行約束,這會導致在刪除引用的鍵后導致報告錯誤。
在這種情況下,確實有助於解除外鍵上的NOT NULL
約束。
create table dog_owner
(id number);
alter table dog_owner add primary key (id);
insert into dog_owner values (1);
create table dog
(id number,
dog_owner_id number not null); -- foreign key is not nullable ..
alter table dog add primary key (id);
alter table dog add foreign key (dog_owner_id) references dog_owner(id)
ON DELETE SET NULL; -- but the contrains sets is to null...
insert into dog values (1,1);
commit;
delete from dog_owner where id = 1;
-- SQL-Fehler: ORA-01407: cannot update ("SCHEMA_NAME"."DOG"."DOG_OWNER_ID") to NULL
alter table dog modify (dog_owner_id number null);
delete from dog_owner where id = 1;
-- 1 rows deleted
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.