inflearn logo
강의

講義

知識共有

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

many-to-many 2

(many to many)에러문구 관련

368

pink321ryu

投稿した質問数 58

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

 

python flask sqlalchemy

回答 1

0

pink321ryu

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

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

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

 

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

 

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

 

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

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

 

작업형 1 유형 부분

0

9

1

수강평 이벤트

0

16

2

작업형 1 (삭제예정, 구 버전)

0

28

2

강의노트는 어디있나요?

0

17

1

노션 학습 자료 권한 요청

0

15

1

수강기간 연장 문의드립니다.

0

20

1

2유형 레이블 인코딩 VS 원핫 인코딩

0

21

3

part2강의 문의사항입니다.

0

19

2

수강기간 연장 문의드립니다.

0

26

1

(등록 웹 페이지 개발 3) relationship등록관련 경고문구

0

287

1

(one-to-many) admin.users.all() 시 출력화면

0

377

1

[db, model2] inflearn 테이블 생성오류시 참고하세요.

0

255

1

use inflearn;

0

313

1

공유 템플릿

0

344

1

run이 작동이 안됩니다ㅠㅠ

0

276

1

서버를 열었을때 404 오류가 납니다

0

277

1

실습 중 질문이 있습니다.

0

555

3

BluePrint 질문입니다.

0

321

1

Project.query.get(1) 질문

0

359

2

db, model2에서 db.create_all()수행시 나타나는 오류입니다..

0

528

1

sql db중에 id 1의 정보가없습니다

0

290

1

relationship 코드위치.

0

167

1

ForeignKey 에러 관련.

0

241

3

Delete가아니고 Update강의가 올라와있네요

0

221

2