2013-11-28 33 views
1
mysql> SHOW COLUMNS from users LIKE 'created_at'; 
+------------+----------+------+-----+---------+-------+ 
| Field  | Type  | Null | Key | Default | Extra | 
+------------+----------+------+-----+---------+-------+ 
| created_at | datetime | NO |  | NULL |  | 
+------------+----------+------+-----+---------+-------+ 
1 row in set (0.00 sec) 

mysql> SHOW VARIABLES LIKE 'innodb_strict_mode'; 
+--------------------+-------+ 
| Variable_name  | Value | 
+--------------------+-------+ 
| innodb_strict_mode | ON | 
+--------------------+-------+ 
1 row in set (0.00 sec) 

mysql> UPDATE `users` SET `created_at` = NULL WHERE `users`.`id` = 200; 
Query OK, 1 row affected, 1 warning (0.02 sec) 
Rows matched: 1 Changed: 1 Warnings: 1 

mysql> SELECT `created_at` from `users` WHERE `users`.`id` = 200; 
+---------------------+ 
| created_at   | 
+---------------------+ 
| 0000-00-00 00:00:00 | 
+---------------------+ 
1 row in set (0.00 sec) 

这是正常行为吗?只是警告。Mysql。用空值更新不为空的列

+0

[**将空到MySQL时间戳**](http://stackoverflow.com/questions/12489078/inserting-null-into-mysql-时间戳/ 12489167#12489167) –

回答

2

是的,它可以是正常的行为。它取决于服务器的SQL模式。数据库可能不是严格模式,并且允许零日期。

此页面上看到更多的细节 - Server SQL Modes:STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_DATE。

检查使用该查询当前SQL模式 -

SHOW VARIABLES WHERE variable_name = 'sql_mode';