Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth app's router 개발 #4

Open
3 tasks done
mathtkang opened this issue Feb 6, 2023 · 1 comment
Open
3 tasks done

auth app's router 개발 #4

mathtkang opened this issue Feb 6, 2023 · 1 comment

Comments

@mathtkang
Copy link
Collaborator

mathtkang commented Feb 6, 2023

  • signup router 개발
  • login router 개발
  • logout router 개발
@mathtkang
Copy link
Collaborator Author

mathtkang commented Apr 14, 2023

signup router 개발시 이슈 발생 및 해결방법

  • 에러메시지: psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "users_user_nickname_key" DETAIL: Key (nickname)=() already exists.
    스크린샷 2023-04-14 오전 1 48 50
  • 참고한 방법: https://www.xmisao.com/2014/06/07/duplicate-key-value-violates-unique-constant-primary-key-on-postgresql.html
  • 해결 방법
    1. DETAIL: Key (nickname)=() already exists. 인 경우: auths app > serializers.pyclass Serializer(ModelSerializer)에서 exclude="nickname"을 추가함
    2. DETAIL: Key (username)=() already exists. 인 경우: 위와 같은 방법으로 했지만 계속 에러 발생
      찐 원인은 바로,,!
    • 나의 User model은 AbstractUser를 상속받기 때문에 (내가 만든) name 속성 뿐만 아니라 username 속성(unique=True)이 자동으로 제공되어 있음이 있음
    • superuser 만들 때는 자동으로 username, email, password를 입력하게 되는데, 내가 구현하고자 한 api에서는 name(not username), email, password를 이용해서 user를 생성함
    • superuser말고, 일반 유저는 1개만 만들어지고 2번째부터 위와 같은 에러메시지가 나오게 된 것임
    • 첫번째 일반 유저를 만들 때, (숨겨져있는) username 속성이 null로 만들어지고, 그 이후의 2번째 유저부터는 username이 unique하다보니 '이미 존재해서' 만들어지지 않게 된 것임
    • (결론) 그래서 User model의 name속성을 없애고 username속성을 사용하기로 함!

이번 에러를 통해 배운 것! 상속받을 때, 어떤 것들을 제공하는지(username이 unique하다는 것도) 더 자세히 알아야겠다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant