inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Phát triển web Python (sử dụng Flask, SQLAlchemy)

Đăng ký Phát triển Trang Web 3

실습 중 질문이 있습니다.

575

likemika1179

6 câu hỏi đã được viết

0

안녕하세요. ipython에서 실습 중 에러가 발생합니다. 

먼저, application.py는 다음과 같이 작성하였습니다.

from flask_sqlalchemy import SQLAlchemy
from flask import Flask

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///C:/jieun/inflearn/form.db'
db = SQLAlchemy(app)

#Role, Member, Project

class Role(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    position = db.Column(db.String(50))
    members = db.relationship('Member'backref = 'role'lazy = 'dynamic')

class Member(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(100))

    role_id = db.Column(db.Integer, db.ForeignKey('role.id'))
    projects = db.relationship('Project'secondary = 'member_project'backref = 'member'lazy = 'dynamic')


class Project(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(100))
    members = db.relationship('Member'secondary='member_project'backref = 'project'lazy = 'dynamic')

db.Table('member_project'
    db.Column('member_id', db.Integer, db.ForeignKey('member.id')),
    db.Column('porject_id', db.Integer, db.ForeignKey('project.id'))
)

그리고 아래는 ipython에서 실습한 내용입니다.

In [1]: from application import db

c:\jieun\inflearn\venv\lib\site-packages\flask_sqlalchemy\__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.

  warnings.warn(FSADeprecationWarning(

In [2]: from application import Role, Member, Project

In [3]: admin = Role(position = 'admin')

c:\jieun\inflearn\venv\lib\site-packages\sqlalchemy\orm\relationships.py:3441: SAWarning: relationship 'Member.project' will copy column member.id to column member_project.member_id, which conflicts with relationship(s): 'Project.member' (copies member.id to member_project.member_id), 'Member.projects' (copies member.id to member_project.member_id). If this is not the intention, consider if these relationships 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.   The 

'overlaps' parameter may be used to remove this warning. (Background on this error at: http://sqlalche.me/e/14/qzyx)

  util.warn(

c:\jieun\inflearn\venv\lib\site-packages\sqlalchemy\orm\relationships.py:3441: SAWarning: relationship 'Member.project' will copy column project.id to column member_project.porject_id, which conflicts with relationship(s): 'Project.member' (copies project.id to member_project.porject_id), 'Member.projects' (copies project.id to member_project.porject_id). If this is not the intention, consider if these relationships 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. 

  The 'overlaps' parameter may be used to remove this warning. (Background on this error at: http://sqlalche.me/e/14/qzyx)

  util.warn(

c:\jieun\inflearn\venv\lib\site-packages\sqlalchemy\orm\relationships.py:3441: SAWarning: relationship 'Project.members' will copy column project.id to column member_project.porject_id, which conflicts with relationship(s): 'Project.member' (copies project.id to member_project.porject_id), 'Member.projects' (copies project.id to member_project.porject_id). If this is not the intention, consider if these relationships 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.   The 'overlaps' parameter may be used to remove this warning. (Background on this error at: http://sqlalche.me/e/14/qzyx)

  util.warn(

c:\jieun\inflearn\venv\lib\site-packages\sqlalchemy\orm\relationships.py:3441: SAWarning: relationship 'Project.members' will copy column member.id to column member_project.member_id, which conflicts with relationship(s): 'Project.member' (copies member.id to member_project.member_id), 'Member.projects' (copies member.id to member_project.member_id). If this is not the intention, consider if these relationships 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.   The 'overlaps' parameter may be used to remove this warning. (Background on this error at: http://sqlalche.me/e/14/qzyx)

  util.warn(

db.create_all()로 form.db 파일은 생성된 상황입니다.

보시고 도움 부탁드립니다~!  

python sqlalchemy flask

Câu trả lời 3

0

kwangsung

이 코드에는 메인함수가 없네요. 아래 주소를 참고해보세요.

https://wikidocs.net/81039

0

likemika1179

여전히 에러가 납니다 .. ㅠㅠ

0

kwangsung

ipython 말고 단순한 python 으로 실행해보세요.

기출 11회 작업형 2_전체 데이터 학습 여부

0

15

1

RateLimitError

0

9

2

예측값 결과 소수점 차이

0

18

2

여태까지 발견한 이슈들 공유드립니다.

1

17

1

기출 문제와 실전챌린지 연습문제 무엇부터 푸는게 나은가요?

0

14

0

전처리 train() test([ ])

0

16

2

작업형 1 배경지식 질문

0

19

2

옳게 풀은건지 질문드립니다!

0

14

1

roc_auc_score

0

22

2

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

0

299

1

(many to many)에러문구 관련

0

379

1

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

0

387

1

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

0

262

1

use inflearn;

0

320

1

공유 템플릿

0

352

1

run이 작동이 안됩니다ㅠㅠ

0

285

1

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

0

286

1

BluePrint 질문입니다.

0

327

1

Project.query.get(1) 질문

0

361

2

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

0

532

1

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

0

291

1

relationship 코드위치.

0

171

1

ForeignKey 에러 관련.

0

242

3

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

0

222

2