Cloud Computing; Windows Azure; .NET Internals; Windows Internals; Column '' in table '' is of a type that is invalid for use as a key column in an index - Paul Lou's blog - Site Home - MSDN Blogs

Column '' in table '' is of a type that is invalid for use as a key column in an index

Column '' in table '' is of a type that is invalid for use as a key column in an index

Rate This
  • Comments 4

I decided to change my blogging style a little bit. Instead of writing lengthy blog posts in a more systematic way I want to write things about all the different kinds of issue I got when building stuff and learning new things. I am very experienced in some areas but new on many more areas so the issues I got might be very basic and simple. I think that it is useful to just record it for myself and also for other people since they might get into the same situation.

I just started using entity framework 6.1.1 and tried to define an index on a column called ZipCode as below but I got the below error when doing 'Update-Database' by using code first migrations.

public string ZipCode { get; set; }

Column 'ZipCode' in table 'dbo.ServiceProviders' is of a type that is invalid for use as a key column in an index.

It turned out that it is a simple issue. The max length for an index column is 900 bytes. The fix is as simple as below.

 [MaxLength(20)]
public string ZipCode { get; set; }
  • Thanks, this saved me from a big problem

  • Thanks ... saved me time :)

  • Thank. You.

    I was chasing this down as  a Data Type issue, rather than just a field length issue.  Saved me a lot of time.

  • Thank you for the blog. Saved me heaps of time.

Page 1 of 1 (4 items)
Leave a Comment
  • Please add 2 and 8 and type the answer here:
  • Post