I've been trying to use sqlalchemy to dump data into a mysql database. When I try to do this, it gives the error sqlalchemy.exc.ArgumentError: List arguments must contain only tuples or dictionaries
. The following code is 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, I'm inserting a list of tuples, but still getting the same error.
Starting with SQLAlchemy version 2, you should use dictionaries instead of tuples:
So this should fix your code: