当尝试插入Postgres数据库时,SQLalchemy执行引擎返回非电视
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现,对于谁找到了这个问题,我做了什么:
将主密钥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.