After adding Index attribute with IsUnique set to true for string value in my code first model

 [Index(IsUnique = true)]
 public string Email { get; set; }

, I've tried to update my database, but got following error:

"column in table is of a type that is invalid for use as a key column in an index".

I've got this error because unique constraint can't be over 8000 bytes per row and will only use the first 900 bytes even then so the safest maximum size for my field would be 450 characters.

To add this limitation in code first model just add following attribute to your property:


Now you can create migration and perform Update-Database command.