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)
这是正常行为吗?只是警告。
答案 0 :(得分:2)
是的,这可能是正常行为。这取决于服务器的SQL模式。数据库可能未处于严格模式,并且允许零日期。
在此页面上查看更多详细信息 - Server SQL Modes:STRICT_ALL_TABLES,STRICT_TRANS_TABLES,NO_ZERO_DATE。
使用此查询检查当前的SQL模式 -
SHOW VARIABLES WHERE variable_name = 'sql_mode';