Django 자동으로 생성된 ContentType, Permission 지우기


상황: 

Django 에서 model 을 만들면,

자동으로 ContentType 과 Permission 이 생성되는데,

이후에 modeld 을 지워도 자동으로 지워지지는 않는다.



해결:

shell 에서 수동으로 지운다.


py manage.py shell


from django.contrib.contenttypes.models import ContentType

ContentType.objects.filter(app_label='your_app', model='your_model').delete()



결과:

(5, {'auth.Permission': 4, 'contenttypes.ContentType': 1})


연결된 Permission 4개도 함께 지워진다.




[보완] 자동으로 지우는 커맨드도 존재한다!


python manage.py remove_stale_contenttypes


Some content types in your database are stale and can be deleted.

Any objects that depend on these content types will also be deleted.

The content types and dependent objects that would be deleted are:


    - Content type for ㅇㅇㅇ.ㅇㅇㅇㅇㅇ

    - 4 auth.Permission object(s)


This list doesn't include any cascade deletions to data outside of Django

models (uncommon).


Are you sure you want to delete these content types?

If you're unsure, answer 'no'.

Type 'yes' to continue, or 'no' to cancel:



이 블로그의 인기 게시물

반올림 올림 내림 버림(절사) 차이와 구현방법

MSSQL SP에서 외부 DLL 사용하는 방법 (CLR 확장저장프로시저)

럭스 원종희 인터뷰 (펌)