SQLAlchemy操作错误:尝试创建新数据库时没有此类表列user_id

2024-04-27 03:50:54 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图在我的帐户页面上添加一个成分时,我得到了下面的错误(它只包括表单AddToPantry-one字段,component\u name)。在

sqlalchemy.exc.OperationalError
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table ingredient has no column named user_id [SQL: 'INSERT INTO ingredient (ingredient_name, user_id) VALUES (?, ?)'] [parameters: ('bread', 1)] (Background on this error at: http://sqlalche.me/e/e3q8)

以下是我的模型:

^{pr2}$

“我的帐户”的“路由”正在加载,该页面的位置是:

@app.route("/account", methods=['GET', 'POST'])
@login_required
def account():
    form = AddToPantry()
    if form.validate_on_submit():
        ingredient = Ingredient(ingredient_name=form.ingredient_name.data, user=current_user)
        db.session.add(ingredient)
        db.session.commit()
    return render_template('account.html', title='Account', form=form)

Tags: nameformiddbsqlalchemyonsession帐户