Search code examples
pythonsqlamazon-web-servicespymysql

AWS RDS MySQL Database not taking INSERT statements from pymysql


So basically what the title says, I can connect to it and make the exact same queries with SQLelectron from my computer (where I am running the script). It doesn't give me errors either, and I can make SELECT queries with sql electron from the same script. What's more is my id column, (on which I have AUTO_Increment enabled) seems to jump to later values when I make the same insert statement from sql electron as if I actually inserted the row, but it does not actually insert. Here is the code snippet:

            sql = ['INSERT INTO liftdb.lifts',
                   '(Date, lift, weight)',
                   'VALUES',
                   '(%s, %s, %s)']
            cur.execute(' '.join(sql), (date, event['Lift'], event['Weight']))

Again, no errors or indication something went wrong.


Solution

  • If your code is acting like theres been a change (by increasing the auto-increment) yet you cant notice any changes, thats a strong indication that you may have forgotten to commit the changes to the database. (something like cur.commit() on the next line down. Assuming you have commited the changes, it could also be that whatever software youre using to check if the database has changed may need to be refreshed in-order to show the changes.