+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| stock_number | varchar(100) | YES | | NULL | |
| year | smallint(6) | YES | | NULL | |
| make | varchar(100) | YES | | NULL | |
| model | varchar(100) | YES | | NULL | |
| color | varchar(100) | YES | | NULL | |
| price | smallint(6) | YES | | NULL | |
| trim | varchar(100) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
7 rows in set (0.00 sec)
mysql> ALTER TABLE trucks ADD PRIMARY KEY(stock_number);
ERROR 1062 (23000): Duplicate entry '' for key 'PRIMARY'
答案 0 :(得分:2)
主键必须是唯一的。该错误消息表明您有多行,其中包含空stock_number
列。在将此列作为主键之前,您需要使用不同的值填充所有这些值。