zoukankan      html  css  js  c++  java
  • Field 'id' doesn't have a default value 原因

    Field 'id' doesn't have a default value昨晚做项目的时候遇到一个问题,在测试数据存储的时候老是报Field 'id' doesn't have a default value异常,从网上找了好久,根据各位大虾的说法也测试了好久好久,可就是没发现原因所在,鼓捣了两三个小时的时间,最后总算找到问题所在:原来是我的数据设计的时候,把主键的类型定义为int的,原本想是用自增的方式来的,可是由于自己的粗心,写sql语句的时候没有加上auto_increment,所以在数据存储的时候老是报Field 'id' doesn't have a default value,id根本就没有值啊!!
    加上自己从网上找的其他人说的他们遇到这种时候的原因,在这里总结一下:
    1、打开my.ini,查找
    sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    修改为
    sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

    然后重启MYSQL

    2、MySQL 5 uses a strict mode which needs to be disabled.
    In Windows, Goto Start-->Programs-->MySQL->MySQL Instance Config Wizard. Follow through the Reconfigure Instance option-->Detailed Configuration-->Continue Next a few screens. At the bottom under Enable TCP/IP option there is 'Enable Strict Mode'. Deslect this option (no tick). Save changes and MySQL will restart.

    3、看看你的数据库定义的时候是不是把主键生成方式设置为int的,但是没有设置为自增的!!或者数据定义的时候设置一个默认值就可以了。

  • 相关阅读:
    前端到后台ThinkPHP开发整站(4)
    前端到后台ThinkPHP开发整站(2)
    字典树模版
    KMP模版
    EXKMP模版
    Manacher模版
    AC自动机练习题1:地图匹配
    AC自动机模版
    spring.net之aop加单例模式编写无try catch程序
    父类与子类之间赋值转换
  • 原文地址:https://www.cnblogs.com/yuhuameng/p/3781119.html
Copyright © 2011-2022 走看看