20

I need to add a unique field index to an existing table. I made this row:

ALTER TABLE auth_user ADD UNIQUE INDEX (email);

The table and the field are already exist. The error is:

Query Error: near "UNIQUE": syntax error Unable to execute statement

What am I missed? Did it have any specific requirements for SQLite3?

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
I159
  • 29,741
  • 31
  • 97
  • 132

1 Answers1

48
CREATE UNIQUE INDEX IF NOT EXISTS MyUniqueIndexName ON auth_user (email)

Also, read the official manual:

http://www.sqlite.org/lang_createindex.html

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123