다른 데이터에서 참조하는 일부 데이터를 새로 고치려고합니다. ms_automobile 테이블을 자르고 다시로드하려고하지만 rm_automobile 테이블에 외래 키가 있습니다.테이블에서 트리거를 비활성화 한 후 외래 키가 활성화되는 이유는 무엇입니까?
이 (포스트 그레스로 실행, 슈퍼 유저) 작업중인 'DISABLE TRIGGER 명령문 다음과 같습니다
mobilesurvey=# ALTER TABLE ms_automobile DISABLE TRIGGER ALL;
ALTER TABLE
mobilesurvey=# ALTER TABLE rm_automobile DISABLE TRIGGER ALL;
ALTER TABLE
하지만 다음 ms_automobile 테이블을자를 수 없습니다 다시
mobilesurvey=# TRUNCATE TABLE ms_automobile;
ERROR: cannot truncate a table referenced in a foreign key constraint
DETAIL: Table "rm_automobile" references "ms_automobile".
HINT: Truncate table "rm_automobile" at the same time, or use TRUNCATE ... CASCADE.
을 , 나는 rm_automobile 데이터를 잃고 싶지 않다. TRUNCATE 후에는 누락 된 ms_automobile 데이터가 포함 된 pg_restore를 수행 할 계획입니다.
가능하면 제약 조건을 삭제하는 대신 비활성화하는 것이 좋습니다. 더 많은 제약이 있으며 사용 중지/사용 유지는 drop/add 유지 관리보다 오류 발생 가능성이 적습니다.
그래서 여기에 어떻게 외래 키를 실제로 비활성화 할 수 있습니까?