I have a dictionary where some of the values might be None. How to insert to mysql data base. I have tried with below,
dict = {'column1': 'test', 'column2': 'test subject', 'Address': None}
query = """insert into tablename (column1,column2,column3) values ('%s', '%s', '%s')""" % (dict['column1'], dict['column1'], dict['column3'])
db_con.execute(query)
But, it's converting None to string and updating in DB. But, I want that field to be null in DB.
How to handle to string and None because the values in dictionary either string or None.
Basically, i want to handle both below dicts,
dict = {'column1': 'test', 'column2': 'test subject', 'Address': 'test'}
dict = {'column1': 'test', 'column2': 'test subject', 'Address': None}