【发布时间】:2017-04-21 10:22:24
【问题描述】:
我有一个带有一些 nvarchar 属性的表。我正在尝试将值插入其中,有时某些值是 NULL。当我尝试将它插入数据库时,它只插入没有空值的元组。这是我的代码的一部分:
self.cursor.execute("INSERT INTO product VALUES (N{0},N{1},N{2},{3})".format(item['name'],item['category'],item['original_price'],item['last_30_days_sales_volume']))
self.connection.commit()
通过以下 try..except 将值插入项目中:
try:
item['last_30_days_sales_volume']= ("\'"+self.driver.find_element_by_xpath('...')+"\'")
except NoSuchElementException, e:
item['last_30_days_sales_volume']= None
任何帮助将不胜感激!
【问题讨论】:
-
仅插入元组意味着什么?它插入带有一些值的元组,它忽略空值,你能举个例子吗
-
如果我尝试插入这样的项目: ('name','cat','$25', 300) 它工作正常,我可以在数据库中找到数据,但如果我尝试insert ('name', None, '$2', 20) 它没有插入它。
-
错误如下:'字段列表'中的未知列'None',但如果我尝试插入'NULL'而不是None,它会插入字符串'NULL'