점프투 플라스크 / 162쪽 질문
안녕하세요.
점프투 플라스크 실습 중
알수없는 syntax error가 계속 떠서.. 질문 드립니다 ㅠㅠ
03-8 실습 중..
init.py를 수정하고
Question 모델에 user_id, user 필드를 추가 후,
flask db migrate를 실행했더니 아래와 같은 에러가 뜹니다.
(venv) C:\flasktest\testa\test>flask db migrate
Traceback (most recent call last):
File "C:\Users\강샘\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\강샘\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\flasktest\testa\venv\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\flasktest\testa\venv\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "c:\flasktest\testa\venv\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\flasktest\testa\venv\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\flasktest\testa\venv\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\flasktest\testa\venv\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\flasktest\testa\venv\lib\site-packages\click\decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 425, in decorator
with __ctx.ensure_object(ScriptInfo).load_app().app_context():
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 388, in load_app
app = locate_app(self, import_name, name)
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 257, in locate_app
return find_best_app(script_info, module)
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 83, in find_best_app
app = call_factory(script_info, app_factory)
File "c:\flasktest\testa\venv\lib\site-packages\flask\cli.py", line 119, in call_factory
return app_factory()
File "C:\flasktest\testa\test\pybo\__init__.py", line 35, in create_app
from . import models
File "C:\flasktest\testa\test\pybo\models.py", line 12
user = db.relationship('User', backref = db.backref('question_set'))
^
SyntaxError: invalid syntax
어디서 잘못되었을까요? ㅠㅠ 도저히 못찾겠습니다..
likemika 님 436
M 2021년 3월 5일 3:46 오후
작성하신 models.py 전체를 보여주세요.
-
박응용님,
2021년 3월 5일 3:46 오후
추천
,
대댓글
@박응용님
from pybo import db
class Question(db.Model):
id = db.Column(db.Integer, primary_key = True)
subject = db.Column(db.String(200), nullable=False)
content = db.Column(db.Text(), nullable=False)
create_date = db.Column(db.DateTime(), nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete='CASCADE', nullable=False)
user = db.relationship('User', backref = db.backref('question_set'))
class Answer(db.Model):
id = db.Column(db.Integer, primary_key = True)
question_id = db.Column(db.Integer, db.ForeignKey('question.id', ondelete='CASCADE'))
question = db.relationship('Question', backref = db.backref('answer_set', ))
content = db.Column(db.Text(), nullable=False)
create_date = db.Column(db.DateTime(), nullable=False)
#회원가입을 위한 모델 p.140
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(150), unique=True, nullable=False)
password = db.Column(db.String(200), nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
-
likemika님,
2021년 3월 5일 3:52 오후
추천
,
대댓글
@박응용님 다시 보다보니 오타를 발견했습니다..ㅠㅠ Question에서 user_id에서 db.ForeignKey의 ( )를 닫아주지 않았네요..ㅠㅠ
-
likemika님,
2021년 3월 5일 4:01 오후
추천
,
대댓글