当尝试插入Postgres数据库时,SQLalchemy执行引擎返回非电视

发布于 2025-02-12 18:30:59 字数 794 浏览 2 评论 0原文

我正在尝试使用python中的Sqlalchemy插入我的Postgres数据库中的表格,并且我会遇到错误返回非类型对象,为什么?我不明白。

from sqlalchemy import create_engine, text
from db.db import engine

def register_new_item(item_name, item_age, item_dress):
    with engine.connect() as conn:
        trans = conn.begin()
        conn.execute(text("""
            INSERT INTO products(
                item_name,
                item_age,
                item_dress
            ) VALUES (
                :item_name,
                :item_age,
                :item_dress
            )               
        """),
            item_name= item_name,
            item_age= item_age,
            item_dress= item_dress
        )
        trans.commit()
        conn.close()

错误: typeError:'nontype'对象不是可叫

I'm trying to insert into a table in my postgres database with sqlalchemy in python and I'm getting error return NoneType object, why? I don't understand.

from sqlalchemy import create_engine, text
from db.db import engine

def register_new_item(item_name, item_age, item_dress):
    with engine.connect() as conn:
        trans = conn.begin()
        conn.execute(text("""
            INSERT INTO products(
                item_name,
                item_age,
                item_dress
            ) VALUES (
                :item_name,
                :item_age,
                :item_dress
            )               
        """),
            item_name= item_name,
            item_age= item_age,
            item_dress= item_dress
        )
        trans.commit()
        conn.close()

error:
TypeError: 'NoneType' object is not callable

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我还不会笑 2025-02-19 18:31:00

我发现,对于谁找到了这个问题,我做了什么:
将主密钥ID从整数更改为串行,以免我通过字段,并且DB创建自己。
返回 @app.after_request调用的函数中的响应。

I findout, for who find this question, what I did:
change the primary key id from INTEGER to SERIAL, to not require that I am pass the field and the db create itself.
return the response inside the function called by the @app.after_request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文