我使用 PostgreSQL 和 flask-sqlalchemy 創建了一個包含 3 個表的資料庫。我正在查詢 3 個表以僅獲取它們的 id,然后我檢查它們的 id 以查看是否有類似的,然后將相似的添加到第三個表中,但是每當我運行它時,我都會收到此錯誤
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) 無法適應型別'Row' [SQL: INSERT INTO login (student_id, name, timestamp) VALUES (%(student_id)s, %(name)s, %(timestamp) s)] [引數:{'student_id': (1234567,), 'name': None, 'timestamp': datetime.datetime(2022, 4, 16, 21, 10, 53, 30512)}]
@app.route('/')
def check():
id = Esp32.query.with_entities(Esp32.student_id).all()
students = Student.query.with_entities(Student.student_id).all()
logins = Login.query.with_entities(Login.student_id).all()
for ids in id:
if ids in students and ids not in logins:
new = Login(student_id= ids)
db.session.add(new)
db.session.commit()
return render_template('check.html', newlog = new)
請有人告訴我這個錯誤是什么意思以及為什么我得到它
uj5u.com熱心網友回復:
id是查詢結果。 ids是查詢行。要從該行中獲取一個值,您需要告訴它哪一列(即使只有一列)ids['student_id]':.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/459292.html
