inflearn logo
강의

Course

Instructor

Complete Guide to Python/Django Web Service Development with React

Implement Follow-Unfollow relationship field in User model and implement Follow function

related_name 오류

267

kwonjiwoo

20 asked

0

안녕하세요 강사님,, 또 오류가 나서 질문 드립니다 ㅜㅜ

class User(AbstractUser):
    class GenderChoices(models.TextChoices):
        MALE = "M", "남성" #전자는 DB에 저장되는 값, 후자는 실제 보여지는 값
        FEMALE = "F", "여성"

    follower_set = models.ManyToManyField(
        "self", blank=True, symmetrical=False,
        related_name="following_set",
    )
    following_set = models.ManyToManyField(
        "self", blank=True, symmetrical=False,
        related_name="follower_set",
    )

이렇게 단방향으로 맞춰주었는데,

저장을 하면

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
accounts.User.follower_set: (fields.E302) Reverse accessor for 'accounts.User.follower_set' clashes with field name 'accounts.User.following_set'.    
        HINT: Rename field 'accounts.User.following_set', or add/change a related_name argument to the definition for field 'accounts.User.follower_set'.
accounts.User.follower_set: (fields.E303) Reverse query name for 'accounts.User.follower_set' clashes with field name 'accounts.User.following_set'.  
        HINT: Rename field 'accounts.User.following_set', or add/change a related_name argument to the definition for field 'accounts.User.follower_set'.
accounts.User.following_set: (fields.E302) Reverse accessor for 'accounts.User.following_set' clashes with field name 'accounts.User.follower_set'.   
        HINT: Rename field 'accounts.User.follower_set', or add/change a related_name argument to the definition for field 'accounts.User.following_set'.
accounts.User.following_set: (fields.E303) Reverse query name for 'accounts.User.following_set' clashes with field name 'accounts.User.follower_set'. 
        HINT: Rename field 'accounts.User.follower_set', or add/change a related_name argument to the definition for field 'accounts.User.following_set'.

계속 이렇게 오류가 뜹니다 ㅜㅜ 왜이럴까요..허허 ㅜㅜ

react python django docker

Answer 1

0

pyhub

안녕하세요.

강의에서는 related_name을 지정하지 않았었는 데, 아래와 같이 related_name을 지정해주신 부분이 다른 점이구요. follower_set의 related_name으로 지정하신 following_set 이름과 그 다음 M2M 필드인 following_set 이름이 충돌이 나서 발생하는 이슈입니다.

image

강의처럼 related_name을 빼시어 처리하셔도 되고, related_name을 지정하실려면 M2M 필드는 둘 중에 하나만 지정하셔도 됩니다.

아래처럼 지정하셔도 동작을 합니다.

image

질문에 감사드립니다.

살펴보시고 댓글 남겨주세요.

화이팅입니다. :-)

안녕하세요.

0

44

1

[OneToOne Field Demo] get_user_model() 메서드를 활용해야 하는 이유?

0

267

1

useEffect 훅에서 else 유무에 따른 결과

0

207

1

useAxios 훅의 dependency array 설정

0

241

1

useEffect에서 변수 업데이트 관련 질문

0

378

1

rest_framework.generics.CreateAPIView의 model 속성 유무

0

262

1

bootstrap4

0

464

4

리뉴얼 강의가 오픈이 되면 기존 강의는 더이상 못보는걸까요

1

357

1

admin form에서 앞선 필드 선택 후 다른 필드 select widget 구성하는 방법

0

568

3

useState는 필수일까요?

0

256

1

python manage.py makemigrations instagram 시 created_at default 오류가 발생합니다.

0

589

4

Django allauth를 사용한 소셜 로그인 시 에러

0

648

1

프로젝트명 변경 뒤, 디버그툴바+디버그모드 사용 시 에러

0

548

2

useLocalStorage() 함수 사용여부

0

223

1

django에 LOGIN_URL = '/accounts/login/'의 의미?

0

443

1

리듀서의 의미 재확인

0

423

1

simple-jwt Refresh Token 사용 노하우

0

894

2

docker compose 를 통한 배포 관련 오류 문의

0

664

1

파이썬 속도 장고 관련 궁금한게 있습니다.

0

357

1

is_like_user

0

227

1

re_path 오류

0

252

1

re_path url

0

243

1

No post matches the given query

0

653

2

sendgrid 메일 발송이 안됩니다 ㅠㅠ

0

884

3