簡體   English   中英

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) 無法適應類型 'Row'

[英]sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'Row'

我使用 PostgreSQL 和 flask-sqlalchemy 創建了一個包含 3 個表的數據庫。 我正在查詢 3 個表以僅獲取它們的 ID,然后我檢查它們的 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)

請有人告訴我這個錯誤是什么意思以及為什么我得到它

id是查詢結果。 ids是一個查詢行。 要從該行獲取一個值,您需要告訴它是哪一列(即使只有一列): ids['student_id]'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM