英文:
unexpected keyword argument in execute statement
问题
def add_application_to_db(job_id, data):
with engine.connect() as conn:
sql = text(
"INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
)
conn.execute(
job_id=job_id,
fullname=data["fullname"],
email=data["email"],
linkedin=data["linkedin"],
education=data["education"],
experience=data["experience"],
resumeurl=data["resumeurl"],
)
英文:
def add_application_to_db(job_id, data):
with engine.connect() as conn:
sql = text(
"INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
)
conn.execute(
job_id=job_id,
fullname=data["fullname"],
email=data["email"],
linkedin=data["linkedin"],
education=data["education"],
experience=data["experience"],
resumeurl=data["resumeurl"],
)
I am learning flask and using MySQL and sqlalchemy.I am trying to store info from user into the data base (table name = application)
I got following error
>TypeError: Connection.execute() got an unexpected keyword argument 'job_id'
答案1
得分: 0
如果您正在使用SQLAlchemy 2.0,则必须将参数发送为字典,而不是您现在尝试的方式。
def add_application_to_db(job_id, data):
row = {
"job_id": job_id,
"fullname": data["fullname"],
"email": data["email"],
"linkedin": data["linkedin"],
"education": data["education"],
"experience": data["experience"],
"resumeurl": data["resumeurl"],
}
with engine.connect() as conn:
sql = text(
"INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
)
conn.execute(sql, row)
英文:
If you are using SQLAlchemy 2.0 then you have to send the parameters as a dict instead of what you are trying now.
def add_application_to_db(job_id, data):
row = {
"job_id": job_id,
"fullname": data["fullname"],
"email": data["email"],
"linkedin": data["linkedin"],
"education": data["education"],
"experience": data["experience"],
"resumeurl": data["resumeurl"],
}
with engine.connect() as conn:
sql = text(
"INSERT INTO application(id,job_id,fullname,email,linkedin,education,experience,resumeurl) VALUES (:job_id,:fullname,:email,:linkedin,:education,:experience,:resumeurl)"
)
conn.execute(sql, row)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论