Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python中为MySQL设置空值_Python_Mysql_Python 2.7_Null_Mysql Python - Fatal编程技术网

如何在Python中为MySQL设置空值

如何在Python中为MySQL设置空值,python,mysql,python-2.7,null,mysql-python,Python,Mysql,Python 2.7,Null,Mysql Python,这是我的SQL命令行版本 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 122 Server version: 5.0.95 Source distribution 我有一个表,在Python中,我想把最后一列写为null。最后,特定行的最后一列将获得一个日期戳,我将使用它作为不再处理该行的标志 +---------------+-------------+------

这是我的SQL命令行版本

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 122
Server version: 5.0.95 Source distribution
我有一个表,在Python中,我想把最后一列写为null。最后,特定行的最后一列将获得一个日期戳,我将使用它作为不再处理该行的标志

+---------------+-------------+------+-----+---------+-------+
| Field         | Type        | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+-------+
| Action        | char(1)     | NO   |     | R       |       | 
| EndpointId    | int(11)     | NO   | MUL | NULL    |       | 
| DeviceType    | smallint(6) | NO   |     | NULL    |       | 
| ChannelNumber | smallint(6) | NO   |     | 0       |       | 
| ActionDate    | date        | YES  |     | NULL    |       | 
| InsertDate    | date        | YES  |     | NULL    |       | 
+---------------+-------------+------+-----+---------+-------+
如何在insert查询字符串中输入null?换句话说,我不知道如何在Python查询字符串中表示NULL

sql_cmd = \
                """insert into cs_remove
                (
                Action, EndpointId, DeviceType, ChannelNumber, ActionDate, InsertDate
                )
                VALUES 
                (
                %s, %s, %s, %s, %s, %s
                )
                """

            print(base_date)
            sql_data = ('R', ept_id, ept_type, ept_ch, "NULL", base_date);

该示例最后将0000-00-00放入日期字符串中。我要空的。我可以从mysql命令行执行此操作,但不能从Python执行。任何帮助都将不胜感激。

您应该使用python中的
None
值来表示您尝试插入的
NULL
mysql值。像这样:

sql_data = ('R', ept_id, ept_type, ept_ch, base_date, None);
以下是另一篇有此问题的帖子:


以及这篇文章:

试着使用
None
。我感觉可能没有。我去试试这个。谢谢