为什么我会收到此错误?MySQL 版本是否发生了一些变化,这会导致这个(在某一时刻有效)现在失败?INSERT INTO 没有指定插入完成时需要的 user_id 值,但由于 id 1 已经存在,这应该成为 UPDATE 并且有效。
mysql> select * from article;
+----+---------+---------------------+-----------+-----------+
| id | user_id | published_at | title | content |
+----+---------+---------------------+-----------+-----------+
| 1 | 1 | 2011-12-10 12:10:00 | article 1 | content 1 |
| 2 | 2 | 2011-12-20 16:20:00 | article 2 | content 2 |
| 3 | 1 | 2012-01-04 22:00:00 | article 3 | content 3 |
+----+---------+---------------------+-----------+-----------+
3 rows in set (0.00 sec)
mysql> desc article;
+--------------+------------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+------------------+------+-----+-------------------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| user_id | int(11) unsigned | NO | MUL | NULL | |
| published_at | datetime | NO | | CURRENT_TIMESTAMP | |
| title | varchar(100) | NO | | NULL | |
| content | text | NO | | NULL | |
+--------------+------------------+------+-----+-------------------+----------------+
5 rows in set (0.01 sec)
mysql> INSERT INTO article (id)
-> VALUES (1)
-> ON DUPLICATE KEY UPDATE title = 'article 1b', content = 'content 1b';
ERROR 1364 (HY000): Field 'user_id' doesn't have a default value
MySQL 版本 5.6.12。