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根本就没有值啊!! 加上本身从网上找的其余人说的他们遇到这种时候的缘由,在这里总结一下: 一、打开my.ini,查找 sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 修改成 sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" 而后重启MYSQL 二、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. 三、看看你的数据库定义的时候是否是把主键生成方式设置为int的,可是没有设置为自增的!!或者数据定义的时候设置一个默认值就能够了。

相关文章
相关标签/搜索