MySQLdb insert queries not working?

So, you’re here on some quest to solve an issue where you do any amount of insert queries through MySQLdb but it doesn’t appear in the database?

Well, I had exactly that issue. Took me ages to figure out why after moving an app to another server (with by design the same database, except for a small difference explained later), the app didn’t insert anything (!!), but didn’t give any errors either.
Thinking to myself: “Weird stuff, can’t be happening!”

So, I went on that quest myself.

Solution is quite simple:

import MySQLdb
db = MySQLdb.connect([...])
c = db.cursor()
[ Couple of insert statements ]
db.commit()

This commit is the key. The reason you’re having the issue is probably because you’re using innoDB as the database engine…

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.