0

Here's my code:

def delete_people(tname, del_name):
    try:
        with connection.cursor() as cursor:

            del_ppl = 'DELETE FROM project3.%s WHERE id = %d; ALTER TABLE project3.%s DROP id; ' \
                      'ALTER TABLE project3.%s ADD id int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; ' \
                      'ALTER TABLE project3.%s AUTO_INCREMENT = 1;'
            cursor.execute(del_ppl % (tname, del_name, tname, tname, tname, ))
            connection.commit()
            print('dltd sucsefuly')


    except Exception as ex:
        print("Connection refused...")
        print(ex)

And when i try to launch this function, i always got this mistake:
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE project3.xcpsdojn DROP id; ALTER TABLE project3.xcpsdojn ADD id int ' at line 1")

I can't understand where's the mistake, because this exact code works in MySQL just fine. I'll appreciate your help!

schinken
  • 1
  • 3
  • I doubt if you can submit more than 1 statement at a time. – P.Salmon Oct 23 '22 at 10:37
  • Does this answer your question? [PyMySQL unable to execute multiple queries](https://stackoverflow.com/questions/58544640/pymysql-unable-to-execute-multiple-queries) – Georg Richter Oct 23 '22 at 11:46

0 Answers0