I am trying to add a column with Unique Key (so it will not have duplicate records) in existing MySQL table that contains multiple rows of data.
ALTER TABLE `common`.`fraud_payment_log`
ADD `retainer_id` VARCHAR( 20 ) NOT NULL,
ADD `http_referrer` VARCHAR( 255 ) NULL ,
ADD UNIQUE (`retainer_id`);
But it is throwing below error:
ERROR 1062 (23000): Duplicate entry '' for key 'retainer_id'
The error is because of the duplicate empty value which will come when we adding a new column in the existing table with records.
Can anyone please suggest how to achieve this?