一个因逻辑不兼容引发的惨案
最近新安装了个MySQL最新版本(MySQL 5.5.20)的数据库,是用安装形式的,安装很简单,一切OK后,因接手一项目,导入其数据后在本机测试,数据插入总是有问题,但同样的程序和插入SQL在以前的服务器上就没问题,总是提示类似下面的错误。
mysql>INSERT INTO users SET email="foobar@example.com", username="foobar", password="secret";ERROR 1364 (HY000): Field 'tags' doesn't have a default value
mysql> desc users;+----------------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------------+---------------------+------+-----+---------+----------------+| id | int(10) unsigned | NO | PRI | NULL | auto_increment || username | varchar(32) | NO | UNI | NULL | || password | varchar(32) | NO | | NULL | || email | varchar(256) | YES | UNI | NULL | || tags | varchar(255) | NO | MUL | NULL | |+----------------+---------------------+------+-----+---------+----------------+50 rows in set (0.01 sec)
# Set the SQL mode to strictsql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
SELECT @@GLOBAL.sql_mode;SELECT @@SESSION.sql_mode;
mysql> SET sql_mode = '';mysql> SELECT NOT 1 BETWEEN -5 AND 5; -> 0mysql> SET sql_mode = 'HIGH_NOT_PRECEDENCE';mysql> SELECT NOT 1 BETWEEN -5 AND 5; -> 1