Reputation: 3
I'm beginning with MySQL, trying to set up a 2-columns primary key, I'm using phpmyadmin.
I managed to somehow mark two columns as a primary key (this is what i have right now, the primary columns are underligned) but they seem to act as two separate primary key, I can't add rows with the same ID and different region, or reversibly the same region and different ID.
What should i fix ? thanks !
Upvotes: 0
Views: 333
Reputation: 6084
If you run SHOW CREATE TABLE
you will most likely see the following:
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
region VARCHAR,
....
PRIMARY KEY (id),
UNIQUE KEY somename (id,region)
So what has been created for you is a unique key. A unique key can be used as primary key, but you will have to get rid of your other primary key id
.
This can be done by:
ALTER TABLE your_table_name DROP PRIMARY KEY;
Since I do not know all your specs, test the result and see if all the desired behavior is still in place.
Upvotes: 1