Проблема в заполнении таблицы mysql
Написал запрос для добавления позиции в таблицу базы данных, но получаю ошибку:
not all arguments converted during string formatting
Вот мой код:
def save_action(id, save):
values = (id, save)
try:
connection = pymysql.connect(
host="localhost",
port=3306,
user="root",
password="soldan1512",
database="kvest_base",
cursorclass=pymysql.cursors.DictCursor
)
print("successfully connected...")
print("#" * 20)
try:
# create table
with connection.cursor() as cursor:
create_table_query = "CREATE TABLE IF NOT EXISTS `save_action`(id int AUTO_INCREMENT," \
" action varchar(32)," \
" PRIMARY KEY (id));"
cursor.execute(create_table_query)
print("Table created successfully")
# insert data
with connection.cursor() as cursor:
insert_query = "INSERT INTO `save_action` (id, action) VALUES (?, ?);"
cursor.execute(insert_query, values)
connection.commit()
finally:
connection.close()
except Exception as ex:
print("Connection refused...")
print(ex)
save_action(1, '2')