【问题标题】:sql insert with null value works on localhost not on live具有空值的sql插入适用于本地主机而不是实时
【发布时间】:2017-04-02 05:06:36
【问题描述】:
INSERT INTO `package`(`cid`,`oid`,`toid`,`cat`,`allday`) values( '3' ,'' ,'5','6','Yes');

当我运行此查询时,它在我的本地主机上运行良好,但在实时服务器上显示错误,因为没有为“oid”指定值,我的实时 mysql 版本是服务器版本:5.6.30-cll-lve - MySQL Community服务器(GPL)

这是我的 oid 字段结构: oid tinyint(4) 非空,

Error i get on live - Field 'oid' is not a integer value

【问题讨论】:

  • oid 的结构是本地的还是远程的?
  • 该查询在本地有效,但在现场无效。

标签: mysql null


【解决方案1】:

由于列不能为 null 并且是 tinyint,它会尝试将空值转换为整数。由于没有给出整数,它会给出你得到的错误。

有两种选择

  1. tinyint(4) not null 改为 tinyint(4) 并赋予 null 值:

    INSERT INTO package(cid,oid,toid,cat,allday) 值('3',null,'5','6','Yes');

  2. 插入一个整数值

    插入package(cid,oid,toid,cat,allday) 值('3','0','5','6','Yes' );

【讨论】:

  • 感谢您的回复。
【解决方案2】:

我不确定,但 oidtinyint(4) NOT NULL 并且您在查询中将空白值存储在 oid 中。请允许 oid 列的空值并尝试以下查询

INSERT INTO `package`(`cid`,`oid`,`toid`,`cat`,`allday`) values( '3' ,null ,'5','6','Yes');
                                                                      ^^

【讨论】:

  • 感谢您的回复。我得到了解决方案。是 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 不允许添加空值。只需将其设置为 sql_mode="" 即可。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 2013-03-02
  • 2014-12-22
  • 1970-01-01
  • 2020-02-10
  • 2017-06-29
  • 1970-01-01
相关资源
最近更新 更多