Heim  >  Artikel  >  Datenbank  >  MySQL之Field‘***’doesn’t have a default value错误解决办法_MySQL

MySQL之Field‘***’doesn’t have a default value错误解决办法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:00:331124Durchsuche

今天,中国博客联盟有博友反馈,zgboke.com无法提交博客,当时我正好准备去假日广场聚会,就匆匆忙忙的提交试了下,发现提交博客的时候确实报如下错误:

提示web_pic不能为空值。很纳闷,之前都可以成功提交的,为什么突然不行了?看了下网上的案例,说是需要修改MySQL的配置什么的,但是目前博客联盟是挂在京东云擎的,数据库不能修改配置,按理说之前可以正常提交,后面应该也可以才对啊!

由于聚会时间快到了,就先放在一边了。回到家之后,对比了下网上的类似案例,原来是web_pic这个键值设置了不为空导致的,也就是在创建表的时候,使用了not null属性。于是进入mywebsql,登入京东云擎数据库,进行了如下操作:

提交后,发现可以成功提交了!出现这个错误的愿意,应该是我最近导入导出数据库太频繁,create tables语句出现错误导致的。

下面,整理一下网上的相同问题的其他解决办法,方便出现问题的同学参考:

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的,但是没有设置为自增的!!或者数据定义的时候设置一个默认值就可以了。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn