I got this code..
.....
try:
task_db.cursor.execute('DROP TABLE IF EXISTS `tasks`')
print "Affected: %d" % task_db.cursor.rowcount
except MySQLdb.Error, e:
print "Error ocurred: %s " % e.args[0]
print e
If the tasks table doesn't exist, then I get a warning like
create_database.py:11: Warning: Unknown table 'tasks'
But if the table does exist then I wont get that warning. Odd?
Catching the MySQLdb.Warning didn't work for me, so I found another way to suppress warnings:
And you can edit the second parameter with whatever you want to suppress.
The most elegant way to avoid Mysql warnings :
It's perfectly correct behaviour. If the table exists, then it's dropped. If it doesn't exist then you get Warning exception which is not the same as Error - you are free to ignore it and nothing bad should happen, but you have to catch it to allow your script to proceed.
EDIT:
To prevent Warning from bubbling up, just catch it as any other exception: