강의

멘토링

커뮤니티

Inflearn コミュニティ Q&A

pink321ryu のプロフィール画像
pink321ryu

投稿した質問数

Python Web開発(Flask、SQLAlchemyを使用)

many-to-many 2

(many to many)에러문구 관련

作成

·

340

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.)

 

pythonflasksqlalchemy

回答 1

0

pink321ryu님의 프로필 이미지
pink321ryu
質問者

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

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

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

 

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

 

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

 

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

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

 

pink321ryu のプロフィール画像
pink321ryu

投稿した質問数

質問する