mysql sqlalchemy.exc.ArgumentError: List argument must consist only of tuples or dictionaries

uurv41yg  于 2022-12-22  发布在  Mysql
关注(0)|答案(1)|浏览(1102)

I have been trying to dump data into a mysql database using sqlalchemy. While I try do so its gives the error sqlalchemy.exc.ArgumentError: List argument must consist only of tuples or dictionaries . The following code is being used for insertion.

def insert_data(db, table, rows):

    db.execute(f"INSERT INTO {table} VALUES (%s)", rows)
    db.commit()

The content in rows is as follows.

[(1, 'asdsewadada', 'lajsdljasld', 'lol@gmail.com', 51)]

So, what I am inserting is list of tuples and I am still getting the same error.

fcipmucu

fcipmucu1#

Can you format your row data like below and give it a try try :

[{"Value1","value2'},{"Value1","value2'}]

相关问题