Reputation: 1
I'm new to the Mysql,so i'm getting the problem while passing the null value to date field from the python script calling the procedure.Can you please help me out
I have table in mysql db_test with fields name and date,date column allows null value.
i call the procedure from python like these
cursor.execute("CALL date_insert(%s,%s) ;" %('john',None))
But it shows an error
Error No:1292 Incorrect value 'None' for the date column
Upvotes: 0
Views: 2635
Reputation: 28405
Try:
cursor.execute("CALL date_insert(%s,%s) ;" % ('john', 'NULL')
Or
cursor.execute("CALL date_insert(%s,%s) ;" % ('john', '\\N')
You might even need:
cursor.execute('CALL date_insert("%s", %s) ;' % ('john', 'NULL')
Just remember that while they are used similarly the various languages:
None, NULL, Null, null, NIL, 0, void, void *, '', "". <>, ?
are not the same and not necessarily interchangeable.
Upvotes: 2
Reputation: 48090
Use:
cursor.execute("CALL date_insert(%s,%s) ;" % ('john', 'NULL')
None
is the Python's way to represent empty objects. MySQL do not have any idea what it is. Instead,MySQL uses 'NULL'
for representing empty values.
Refer "MySQL - Working with Null" for more details.
Upvotes: 0
Reputation: 4912
Try NULL
instead of None
for MYSQL:
cursor.execute("CALL date_insert(%s,%s) ;" %('john','NULL'))
Upvotes: 0