Duplicate key name 'unique_id'
11,407
remove this line
UNIQUE KEY `unique_id` (`unique_id`),
since unique_id
is already Primary Key
. and Primary Keys
are unique.
full CREATE TABLE
statement
create table `users`
(
uid int(11) auto_increment,
unique_id varchar(23) not null,
name varchar(50) not null,
email varchar(100) not null unique, -- specified here
encrypted_password varchar(80) not null,
salt varchar(10) not null,
created_at datetime,
updated_at datetime null,
PRIMARY KEY (`unique_id`),
UNIQUE KEY `uid` (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=877888
DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Author by
william007
Updated on June 29, 2022Comments
-
william007 almost 2 years
Here is the sql, however, there is an error says "*#1061 - Duplicate key name 'unique_id'* ", what is the problem.
create table `users`( uid int(11) auto_increment, unique_id varchar(23) not null unique, name varchar(50) not null, email varchar(100) not null unique, encrypted_password varchar(80) not null, salt varchar(10) not null, created_at datetime, updated_at datetime null, PRIMARY KEY (`unique_id`), UNIQUE KEY `uid` (`uid`), UNIQUE KEY `unique_id` (`unique_id`), UNIQUE KEY `email` (`email`) )ENGINE=InnoDB AUTO_INCREMENT=877888 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;