ALTER TABLE `table` ADD `unionid` VARCHAR( 255 ) NOT NULL
然后设置唯一索引
ALTER TABLE `table` ADD UNIQUE (
`unionid`
)
提示
请问这是为什么呢?
PHP中文网2017-04-17 15:34:49
The first SQL sentence: You added a table
column to the unionid
table, and it is a non-empty string, so the initial value is an empty string ''
;
Second SQL sentence: You establish a unique constraint on the table
column of the unionid
table, but the premise of the unique constraint is that the values of the unionid
column are not repeated. However, all values of the unionid
column are null characters. string ''
, so it will report Duplicate entry '' for key 'unionid'
.
Solution: First correct the value of unionid
to be non-repeating and then add a unique constraint to the column.
PHP中文网2017-04-17 15:34:49
Go directly to the database to operate. When you add an index, there will be a command prompt, so you will know what is wrong