django model Foreign Key on_delete

BackEnd_Ash.log·2020년 2월 26일
0

1. CASCADE

    postcode_id = models.ForeignKey('Postcodes', on_delete=models.CASCADE)

의 경우 ForeignKeyField 가 바라보는 값이 삭제될때 ,
ForeignKeyField 를 포함하는 모델 인스턴스 (row) 도 삭제된다.

2 . SET_NULL

ForeginkeyField 가 바라보는 값이 삭제될 때 ForeignKeyField 값을 null 로 바꾼다.
(null = True 일 때만 가능 )

3. SET_DEFAULT

ForeginkeyField 가 바라보는 값이 삭제될 때 ForeignKeyField 값을 default 값으로 바꾼다.
(default 값이 있을때만 가능 )

ForeignKeyField('User' , on_delete=models.SET_DEFAULT )

4. PROTECT

ForeignKeyField 가 바라보는 값이 삭제될 때 삭제가 되지않도록 ProtectedError 를 발생시킨다.

ForeignKeyField('User' , on_delete=models.PROTECT)

참고자료 :

https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.ForeignKey

profile
꾸준함이란 ... ?

0개의 댓글