Reputation: 40633
I have a table that is in production. I realize that some of the columns should be unique. Is it safe to go into phpMyAdmin and change those columns to make it unique?
ALTER TABLE `foo` ADD UNIQUE ( `bar` )
Upvotes: 30
Views: 87104
Reputation: 990
Follow the below steps to apply unique column value from phpmyadmin panel:
Go to the table structure. Click on the unique keyword as like below -
Click on the ok from confirmation box -
Unique value constraint for column will apply. Or you can run mysql query:
ALTER TABLE user ADD UNIQUE(email);
Upvotes: 36
Reputation: 1515
I had this problem and my values were not unique. I also couldn't find an easy way to edit this problem in PHPMyAdmin. Here's how I solved it:
I clicked into the table I needed to update
I exported the table, changing it to be a CSV export and then edited it manually to update the non-unique values.
Hope that saves someone some time in the future.
Upvotes: 1
Reputation: 53597
One more thing, if you have a prod DB, you must also have a dev DB which you can test on without fear, right?
Upvotes: 17
Reputation: 29166
If there are already some duplicate values in those columns, then this will generate an error. If there aren't any duplicate values in those columns, then you will be fine.
Upvotes: 2
Reputation: 18488
It will only be a problem if the pre-existing values on the table are not unique, otherwise I don't think there will be any problem.
Upvotes: 1