【问题标题】:How to insert null value to int column in MySQL using python 2.7如何使用 python 2.7 将空值插入 MySQL 中的 int 列
【发布时间】:2020-05-05 08:27:48
【问题描述】:

尝试使用 python 将空值插入 MySql 表。下面是执行的代码

sql="""insert into db.table_name (int_column, column2) values (None, 'test')"""
cursor.execute(sql)

运行时遇到错误

mysql.connector.errors.ProgrammingError: 1054 (42s22) : 未知列 “字段列表”中的“无”

参考this solution 对此进行了尝试

【问题讨论】:

  • values (null, 'test')

标签: mysql sql python-2.7


【解决方案1】:

尝试以下操作,将您的 none 替换为 null

sql="""insert into db.table_name (int_column, column2) values (null, 'test')"""
cursor.execute(sql)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2018-03-31
    • 1970-01-01
    • 2016-06-17
    相关资源
    最近更新 更多