• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

(many to many)에러문구 관련

24.01.21 10:30 작성 조회수 119

0

안녕하세요.

그대로 코드를 진행했는데요. 상호참조하는 것 관련해서 에러가 나는데 그냥 무시를 해도 될까요?

=>

admin = Role(position='admin') 실행시 에러문구

workspace/inflearn_240120/venv/bin/ipython:1: SAWarning: relationship 'User.project' will copy column user.id to column user_project.user_id, which conflicts with rel

ationship(s): 'Project.user' (copies user.id to user_project.user_id), 'User.projects' (copies user.id to user_project.user_id). If this is not the intention, consider

if theserelationships should be linked with back_populates, or if viewonly=True should be applied to one or more if they are read-only. For the less common case that

foreign key constraints are partially overlapping, the orm.foreign()annotation can be used to isolate the columns that should be written towards. To silence this war

ning, add the parameter 'overlaps="projects,user"' to the 'User.project' relationship. (Background on this warning at: https://sqlalche.me/e/20/qzyx) (This warning ori

ginatedfrom the configure_mappers() process, which was invoked automatically in response to a user-initiated operation.)

 

답변 1

답변을 작성해보세요.

0

류재안님의 프로필

류재안

질문자

2024.01.22

backref ='user' -> back_populates='users'

backref='project' -> back_populates='projects'

로 수정하니 경고문구가 없어졌고 실행도 잘 되는데요.

 

Document를 여러번 읽어보니, 헷갈리기는 한데요..

 

backref를 사용할 때는 parent 이든 child 이든 한쪽에만 하고 양쪽으로는 back_populates 를 넣는 듯 한데..

 

사실 sqlalchemy 에서 이 관계설정이 핵심일 거 같은데.

혹시 추가적인 설명을 좀 해주실 수 있을지요?